在spring中引入其他配置文件,使用import导入。
<import resource="classpath:serviceConfig/mybatis.xml" />
<import resource="classpath:serviceConfig/mailService.xml" />
<import resource="classpath:serviceConfig/quartzService.xml" />
<import resource="classpath:serviceConfig/threadPool.xml" />
properties文件的引入方式分两种。
1.在spring.xml文件中统一引入。
2.在使用该properties文件的的xml配置文件中分别引用。
下面是两种引入方式:
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/jdbc.properties</value>
<value>classpath:properties/mail.properties</value>
</list>
</property>
</bean>
<!--引入属性文件 -->
<context:property-placeholder
location="classpath:properties/mail.properties"
ignore-unresolvable="true"/>
<!--引入属性文件 -->
<context:property-placeholder
location="classpath:properties/jdbc.properties"
ignore-unresolvable="true"/>
一定要声明ignore-unresolvable="true",否则tomcat启动会报错。
不过,你也可以把这两个属性文件都写在spirng.xml中,不过这样我更推荐第一种方式了。
另外,对于properties文件还是统一管理会比较好。