Multiple profiles for specific applications:
More relational configuration file:
- Juxtaposed
- contain
Constellation
That there are multiple configuration files, which need to load multiple configuration files at the same time;
The variable parameters can be used, and an array of wildcards loaded;
- variable parameter
String config1 = "com/abc/di08/spring-student.xml";
String config2 = "com/abc/di08/spring-school.xml";
//加载配置文件,生成spring容器对象(多个字符串参数加载多个配置文件)
ApplicationContext ac = new ClassPathXmlApplicationContext(config1,config2);
- Load Array
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);
- Wildcard load
String config = "com/abc/di08/spring-*.xml";
//加载配置文件,生成spring容器对象(通配符加载多个配置文件)
ApplicationContext ac = new ClassPathXmlApplicationContext(config);
Inclusion relation
First, load the master configuration file, and then using wildcards load another profile in the main configuration file.
String config = "com/abc/di09/applicationContext.xml";
ApplicationContext ac = new ClassPathXmlApplicationContext(config);
<!--import标签加载包含配置文件-->
<import resource="spring-*.xml"/>