现在的位置: 首页 > 编程语言 > 正文

spring如何加载配置多个配置文件

2020年02月13日 编程语言 ⁄ 共 1057字 ⁄ 字号 评论关闭

这篇文章主要介绍了spring如何加载配置多个配置文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

为应用指定多个配置文件:

多个配置文件的关系:

并列 包含

并列关系

即有多个配置文件,需要同时加载这多个配置文件;

可以使用可变参数,数组和统配符进行加载;

可变参数

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"/>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: spring如何加载配置多个配置文件

以上就上有关spring如何加载配置多个配置文件的相关介绍,要了解更多spring,加载,配置,文件内容请登录学步园。

抱歉!评论已关闭.