spring 配置文件的整合

假如有多个配置文件,分别在不同的目录。

  • Spring-X01.xml 位于 conf01 文件夹里
  • Spring-X02.xml 位于 conf02 文件夹里
  • Spring-X03.xml 位于 conf03 文件夹里
    传统的加载方式:
1
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"Spring-X01.xml","Spring-X02.xml","Spring-X03.xml"})

整合配置文件到一个配置文件里,创建一个Spring-All-Module.xml文件

1
2
3
4
5
<beans ....>
<import resource="conf1/Spring-X01.xml"/>
<import resource="conf2/Spring-X02.xml"/>
<import resource="conf3/Spring-X03.xml"/>
</beans>

整合之后的加载方式:

1
ApplicationContext context = new ClassPathXmlApplicationContext("Spring-All-Module.xml");