Spring多配置文件使用
Spring会根据需要,把配置信息分门别类的放置在多个配置文件中,便于后续的管理及维护。
DAO ------ applicationContext-dao.xml
Service --- applicationContext-service.xml
Action --- applicationContext-action.xml
注意:虽然提供了多个配置文件,但是后续应用的过程中,还要进行整合 。
1. 通配符方式
-
非web环境
ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext-*.xml");
-
Web环境
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</paramvalue> <context-param>
2. 使用import标签
定义一个主配置文件,在主配置文件中进行配置。
applicationContext.xml ⽬的 整合其他配置内容
<import resource="applicationContext-dao.xml" />
<import resource="applicationContext-service.xml" />
<import resource="applicationContext-action.xml" />