分模块配置
1.在加载配置文件的时候,加载多个
例如把applicationContext.xml配置文件中的关于集合配置的部分剪切到applicationContext2.xml中,在加载配置文件的时候,将两个配置文件全部加载。
public class SpringDemo5 {
@Test
public void demo1(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext2.xml");
CollectionBean collectionBean= (CollectionBean)applicationContext.getBean("collectionBean");
System.out.println(collectionBean);
}
}
2.在一个配置文件中引入多个配置文件
在applicationContext.xml中用import标签引入applicationContext2.xml:
<import resource="applicationContext2.xml"/>
因为两个配置文件在同一个根目录下,所以可以直接写名字。