在使用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" /> ...
可以使用通配符设置,如下所示:
<import resource="beanconfigs/applicationContext_*.xml" />
这样在spring配置就可以写成如下所示:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:applicationContext_all.xml </param-value> </context-param>