spring加载jar包中多个配置文件

来源:互联网 发布:电脑卸载不了软件 编辑:程序博客网 时间:2024/06/02 04:16

 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示:

<context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:beanconfigs/applicationContext_1.xml,classpath*:beanconfigs/applicationContext_2.xml,...</param-value></context-param>

 

这样太复杂了,对于一个大的项目而言,要在这里写入太多的配置,影响美观还害怕引入的xml减少。可以自定义一个applicationContext_all.xml,使用import引入其他配置文件,如下所示:

<import resource="beanconfigs/applicationContext_1.xml" /><import resource="beanconfigs/applicationContext_2.xml" />...

这样在spring配置就可以写成如下所示:

<context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:applicationContext_all.xml</param-value></context-param>
原创粉丝点击