首先要保证所有加载属性的配置(例如:路径、名称....)都没问题,然后出现该错误的原因可能是web项目中,出现了多个properties为扩展名的文件,然后使用了多个<context:properties-placeholder>去加载每个配置文件
<context:property-placeholder>提供了加载外在参数的配置,当时默认情况下该标签只能spring出现一份,或者是下述配置情况也会出现上述问题
如一个配置文件中使用了
<context:property-placeholder location="classpath:aa.properties" />
而另一处使用了(这里的配置等效第二次使用了<context:property-placeholder>)
<bean id="propertyConfigurer">
<!--class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
<property name="locations">-->
<list>
<value>classpath:bb.properties</value>
</list>
</property>
</bean>
解决办法:
1、如果一处使用了propertyConfigurer,将其替换为标签<context:property-placeholder>
2、在所有的<context:property-placeholder>中,修改属性配置ignore-unresolvable(默认为false)为true
类似这样:
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:resource.properties" ignore-unresolvable="true"/>
ignore-unresolvable:是否忽略解析不到的属性,如果不忽略,找不到将抛出异常
解决spring加载多个properties文件的问题