您的位置:首页 > 其它

could not resolve placeholder ${}

2016-03-07 11:28 190 查看
用spring 配置加载properties文件的时候,报Could not resolve placeholder 错误。
很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因或者是多个PropertyPlaceholderConfigurer与<context:property-placeholder>混合使用。
解决方案:
在Spring3中可以用如下方式解决,找到所有[color=blue]<context:property-placeholder>[/color]
增加[color=red]ignore-unresolvable="true"[/color]属性,注意必须都要加上
<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" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: