Could not resolve placeholder 解决方案
发布日期:2021-07-12 08:49:04 浏览次数:8 分类:技术文章

本文共 1502 字,大约阅读时间需要 5 分钟。

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

Could not resolve placeholder 错误。
经过仔细查找,排除文件路径,文件类容错误的原因,经过查找相关资料,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因或者是多个PropertyPlaceholderConfigurer与<context:property-placeholder>混合使用。
如果配置如下一定会报以上错误,不管是在多个配置文件中还是分别在不同文件中

 

  1. <context:property-placeholder location="WEB-INF/config/db/XX.properties" />   
  2. <context:property-placeholder location="WEB-INF/config/dfs/XX.properties" />  
解决方案:
在Spring3中可以用如下方式解决,增加ignore-unresolvable="true"属性,注意必须都要加上

 

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

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

 

  1. <bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  2.     <property name="location" value="xxx.properties" />  
  3.     <property name="ignoreUnresolvablePlaceholders" value="true" />   
  4. </bean>  
系统中如果报如上错误,可以这样查找:搜索系统中所有包含property-placeholder的文件,看是否包含ignore-unresolvable属性,然后搜索系统中所有包含PropertyPlaceholderConfigurer文件,看是否包含ignoreUnresolvablePlaceholders属性。
 
今天系统中报如上错误,就是因为按照PropertyPlaceholderConfigurer方式没有配置ignoreUnresolvablePlaceholders属性,而按照context:property-placeholder方式配置的都包含了ignore-unresolvable属性。
 
 
归根到底就是规范没到位,加载配置文件没统一

转载于:https://www.cnblogs.com/wq3435/p/7161907.html

转载地址:https://blog.csdn.net/ankan7400/article/details/102088908 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Servlet 3.0 新特性详解
下一篇:Storm的并行度、Grouping策略以及消息可靠处理机制简介

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月17日 06时23分37秒