标签:classpath 加载 string 数组 ica conf 数加 关系 pre
多个配置文件的关系:
即有多个配置文件,需要同时加载这多个配置文件;
可以使用可变参数,数组和统配符进行加载;
String config1 = "com/abc/di08/spring-student.xml";
String config2 = "com/abc/di08/spring-school.xml";
//加载配置文件,生成spring容器对象(多个字符串参数加载多个配置文件)
ApplicationContext ac = new ClassPathXmlApplicationContext(config1,config2);
String config1 = "com/abc/di08/spring-student.xml";
String config2 = "com/abc/di08/spring-school.xml";
String[] configs = {config1,config2};
//加载配置文件,生成spring容器对象(数组加载多个配置文件)
ApplicationContext ac = new ClassPathXmlApplicationContext(configs);
String config = "com/abc/di08/spring-*.xml";
//加载配置文件,生成spring容器对象(通配符加载多个配置文件)
ApplicationContext ac = new ClassPathXmlApplicationContext(config);
首先加载主配置文件,然后在主配置文件中使用通配符加载另外的配置文件。
String config = "com/abc/di09/applicationContext.xml";
ApplicationContext ac = new ClassPathXmlApplicationContext(config);
<!--import标签加载包含配置文件-->
<import resource="spring-*.xml"/>
标签:classpath 加载 string 数组 ica conf 数加 关系 pre
原文地址:https://www.cnblogs.com/gbetter/p/11827252.html