could not resolve placeholder ${}

用spring 配置加载properties文件的时候,报Could not resolve placeholder 错误。
很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因或者是多个PropertyPlaceholderConfigurer与<context:property-placeholder>混合使用。
解决方案:
在Spring3中可以用如下方式解决,找到所有 <context:property-placeholder>
增加 ignore-unresolvable="true"属性,注意必须都要加上
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"  />  


在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的
<bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
    <property name="location" value="xxx.properties" />  
    <property name="ignoreUnresolvablePlaceholders" value="true" />   
</bean>  


这次报错因为配了 <property name="ignoreUnresolvablePlaceholders" value="true" /> 而没有配置<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"  />

猜你喜欢

转载自278653219.iteye.com/blog/2281025