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

Could not resolve placeholder 错误。

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

如果配置如下一定会报以上错误,不管是在多个配置文件中还是分别在不同文件中

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

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

<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" />与下面的配置是等价的

<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属性。

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

 

 

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

转自:https://my.oschina.net/u/1584569/blog/323491

Could not resolve placeholder 解决方案的更多相关文章

  1. Spring中报"Could not resolve placeholder"的解决方案

    除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...

  2. Spring中报"Could not resolve placeholder"的解决方案(引入多个properties文件)

    除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...

  3. 【转】Spring项目启动报"Could not resolve placeholder"解决方法

    问题的起因: 除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceho ...

  4. Spring项目启动报"Could not resolve placeholder"解决

    1.问题的起因: 除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlace ...

  5. spring错误<context:property-placeholder>:Could not resolve placeholder XXX in string value XXX

    spring同时集成redis和mongodb时遇到多个资源文件加载的问题 这两天平台中集成redis和mongodb遇到一个问题 单独集成redis和单独集成mongodb时都可以正常启动程序,但是 ...

  6. spring错误:<context:property-placeholder>:Could not resolve placeholder XXX in string value XXX

    spring同时集成redis和mongodb时遇到多个资源文件加载的问题 这两天平台中集成redis和mongodb遇到一个问题 单独集成redis和单独集成mongodb时都可以正常启动程序,但是 ...

  7. Could not resolve placeholder

    使用spring的<context:property-placeholder location="/WEB-INF/redis.properties"/>读取prope ...

  8. Springboot 2.x 无法读取yml配置值的问题:Could not resolve placeholder xxx value '${xxx}'

    最近在用Springboot2.1 新建demo工程的时候,在DataSourceConfig类中通过 @Value("${spring.datasource.url}") 的方式 ...

  9. IDEA报错: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"

    运行审核流模块: 在ActivitiServiceApplication模块日志报错: Error starting ApplicationContext. To display the auto-c ...

随机推荐

  1. SQLServer2008R2企业版密匙

    SQLServer2008R2企业版密匙:  R88PF-GMCFT-KM2KR-4R7GB-43K4B 

  2. CSS盒子模型元素实际宽度的计算

    一旦为页面设置了恰当的 DTD,大多数浏览器都会按照上面的图示来呈现内容.然而 IE 5 和 6 的呈现却是不正确的.根据 W3C 的规范,元素内容占据的空间是由 width 属性设置的,而内容周围的 ...

  3. matlab画柱状图

    论文中需要画图进行比较,感觉还是matlab画起来比较方便,先把自己画的图及matlab代码放上. y=[300 311;390 425; 312 321; 250 185; 550 535; 420 ...

  4. Myeclipse中添加XFire插件支持

    自Myeclipse7.5后貌似默认不启用XFire插件的集成  本人今天使用Myeclipse10.6是发现没有XFire 自己捣鼓捣鼓 已经成功添加XFire 添加步骤 1.打开Myeclipse ...

  5. Node判断文件是否链接

    通过fs.stat(), fs.lstate() and fs.fstate()都可以得到fs.Stats对象, 其中stats.isSymbolicLink()方法用来判断是否链接, 然而一直都不成 ...

  6. WEB进度条控件

    近段时间为了工作的需要学习了一下写自定义控件,呵呵!以前没写过,近段时间才开始研究的,昨天写了一个WEB状态条控件,可以设置进度条的百分比,也可以设置它的总数与当前的数量来自动计算百分比,可以设置颜色 ...

  7. SQL行转列+动态拼接SQL

    数据源       Name AreaName qty Specific 叶玲 1 60 1 叶玲 2 1 1 叶玲 6 1 0 叶玲 7 5 0 叶玲 8 1 1 显示效果: Name 1 2 8 ...

  8. Linux中的命令 make -f 是什么意思

    出处:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c422460 ...

  9. Salesforce 执行顺序

    在服务器上,Salesforce按以下顺序执行: 1,从数据库加载原始记录或初始化一个用于更新插入(upsert)语句的记录. 2,从请求加载新记录的字段值并覆盖旧的值. 如果请求来自一个标准的UI( ...

  10. 5. 网络配置与FTP服务笔记

    IP地址: Ipv4        2*32       Ipv6 tcp      网络通讯协议 udp    用户数据报协议 常见网络端口: 20  21      ftp服务 文件共享 22   ...