【转】Could not resolve placeholder 解决方案

spring 配置加载properties文件的时候,报spring

Could not resolve placeholder 错误。spa

通过仔细查找,排除文件路径,文件类容错误的缘由,通过查找相关资料,出现"Could not resolve placeholder"颇有多是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的缘由或者是多个PropertyPlaceholderConfigurer与<context:property-placeholder>混合使用。code

若是配置以下必定会报以上错误,无论是在多个配置文件中仍是分别在不一样文件中it

<context:property-placeholder location="WEB-INF/config/db/XX.properties" />   <context:property-placeholder location="WEB-INF/config/dfs/XX.properties" />


解决方案:
在Spring3中能够用以下方式解决,增长ignore-unresolvable="true"属性,注意必须都要加上io

<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"  />  <context:property-placeholder location="yyy.properties" ignore-unresolvable="true"  />

在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时能够改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的class

<bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">      <property name="location" value="xxx.properties" />      <property name="ignoreUnresolvablePlaceholders" value="true" />   </bean>


系统中若是报如上错误,能够这样查找:搜索系统中全部包含property-placeholder的文件,看是否包含ignore-unresolvable属性,而后搜索系统中全部包含PropertyPlaceholderConfigurer文件,看是否包含ignoreUnresolvablePlaceholders属性。stream

今天系统中报如上错误,就是由于按照PropertyPlaceholderConfigurer方式没有配置ignoreUnresolvablePlaceholders属性,而按照context:property-placeholder方式配置的都包含了ignore-unresolvable属性。配置



归根到底就是规范没到位,加载配置文件没统一搜索

相关文章
相关标签/搜索