在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檔案還是統一管理會比較好。