Spring的分模块开发的配置

参考:Spring学习笔记—Spring的分模块开发的配置

在加载配置文件的时候,加载多个

例如把applicationContext.xml配置文件中的关于集合配置的部分剪切到applicationContext2.xml中,在加载配置文件的时候,将两个配置文件全部加载。

1
2
3
4
5
6
7
8
public class  {

public void demo1(){
大专栏  Spring的分模块开发的配置"> ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext2.xml");
CollectionBean collectionBean= (CollectionBean)applicationContext.getBean("collectionBean");
System.out.println(collectionBean);
}
}

在一个配置文件中引入多个配置

在applicationContext.xml中用import标签引入applicationContext2.xml:

1
<import resource="applicationContext2.xml"/>

因为两个配置文件在同一个根目录下,所以可以直接写名字。

原文地址:https://www.cnblogs.com/lijianming180/p/12375890.html