在项目开发中,伴随着功能越来越多,对于spring自动加载一个applicationContext.xml文件,会出现文件很大的情况。
所以可以采取分文件配置的方式
1.在applicationContext.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<import resource="base.xml"/>
</beans>
2.然后编写一个base.xml和上一个文件同一个目录下
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- DicBase -->
<bean id="DicBaseDao" class="com.dicbase.DicBaseDaoImpl"></bean>
<bean id="DicBaseService" class="com.dicbase.DicBaseServiceImpl">
<property name="dao">
<ref bean="DicBaseDao"/>
</property>
</bean>
</beans>