Spring如何加载多个xml文件

1.场景还原

    在实际项目中,xml配置文件有可能有多个,如何在项目启动的时候一次性的将多个文件成功的加载进去呢?这也是笔者今天要跟老铁们分享的issue

2.解决方案

①项目启动时加载配置

在web.xml中配置如下

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml,classpath:spring-rabbitmq.xml</param-value>
</context-param>

②在测试用例类中配置如下

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext.xml", "classpath:/spring-rabbitmq.xml" })
好了,我是张星,欢迎加入博主技术交流群,群号:313145288

猜你喜欢

转载自blog.csdn.net/zhangxing52077/article/details/79941474