spring 加载多个配置文件

spring导入配置文件一般使用的是
<context:property-placeholder location="classpath:xxx.properties"/>
当导入单个文件的时候是不会出现问题的,但是当需要导入多个配置文件的时候就会出现问题,比如:
<context:property-placeholder location="classpath:xxx.properties"/>
<context:property-placeholder location="classpath:yyy.properties"/>
有两种解决办法
第一种将
<context:property-placeholder location="classpath:xxx.properties"/>
<context:property-placeholder location="classpath:yyy.properties"/>
改为
<context:property-placeholder location="classpath:xxx.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:yyy.properties" ignore-unresolvable="true"/>
第二种
<bean id="propertyConfigurer"
   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:xxx.properties</value>
<value>classpath:yyy.properties</value>
</list>
</property>
</bean>

个人觉得第二种更好,便于配置和管理

猜你喜欢

转载自he7ning3.iteye.com/blog/2215933