除去properites文件路径错误、拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因。

  比如我有一个dao.xml读取dbConnect.properties,还有一个dfs.xml读取dfsManager.properties,然后web.xml统一load这两个xml文件

  1. <context-param>
  2. <param-name>contextConfigLocation</param-name>
  3. <param-value>
  4. WEB-INF/config/spring/dao.xml,
  5. WEB-INF/config/spring/dfs.xml
  6. </param-value>
  7. </context-param>

如果这两个xml文件中分别有

  1. <!-- dao.xml -->
  2. <context:property-placeholder location="WEB-INF/config/db/dbConnect.properties" />
  3. <!-- dfs.xml -->
  4. <context:property-placeholder location="WEB-INF/config/dfs/dfsManager.properties" />

那么,一定会出"Could not resolve placeholder"。

  一定要记住,不管是在一个Spring文件还是在多个Spring文件被统一load的情况下,直接写

  1. <context:property-placeholder location="" />
  2. <context:property-placeholder location="" />

是不允许的。

解决方案:

  (1) 在Spring 3.0中,可以写:

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

注意两个都要加上ignore-unresolvable="true",一个加另一个不加也是不行的

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

  1. <bean id="随便" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  2. <property name="location" value="xxx.properties" />
  3. <property name="ignoreUnresolvablePlaceholders" value="true" />
  4. </bean>

  正因为如此,写多个PropertyPlaceholderConfigurer不加ignoreUnresolvablePlaceholders属性也是一样会出"Could not resolve placeholder"。

  虽然两者是的等价的,但估计大家还是喜欢写<context:property-placeholder>多一些,毕竟简单一些嘛。所以如果是Spring 3.0,直接用解决方案(1)再简单不过了;如果是Spring 2.5,需要费点力气改写成PropertyPlaceholderConfigurer

Spring中报"Could not resolve placeholder"的解决方案的更多相关文章

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

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

  2. Spring 出现Could not resolve placeholder问题的解决方法

    项目开发中,使用@value注解获取不到配置文件里面的属性字段. 检查配置文件,在spring的配置文件中有配置读取,如下: <!-- 使用spring自带的占位符替换功能 --> < ...

  3. spring cloud config---Could not resolve placeholder 'xxx' in string value "${xxx}"

    初学SpringCloud 跟着视频写配置 前前后后检查了许久,配置代码没问题 最后发现是client项目的配置文件名有问题,不应该是application.yml 而是bootstrap.yml 那 ...

  4. Could not resolve placeholder 解决方案

    spring 配置加载properties文件的时候,报 Could not resolve placeholder 错误. 经过仔细查找,排除文件路径,文件类容错误的原因,经过查找相关资料,出现&q ...

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

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

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

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

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

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

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

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

  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. LeetCode之Easy篇 ——(7)Reverse Integer

    7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...

  2. Memcached修改默认端口

    windows下修改memcached服务的端口号(默认端口:11211)如果不是作为服务启动memcached的话,memcached -p 端口号就可以了. 通过修改注册表可以简单实现 运行:re ...

  3. 题目1010:A + B

    题目描述: 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. 输入: 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B ...

  4. NYOJ一种排序

    //最重要的收获就是懂得了,还可以调用库函数直接对结构体进行排序sort(const void *,const void *,cmp) /* bool cmp(rect c,rect d) { if( ...

  5. MySQL Connector 卸载

    MySQL Connector 安装的时候有时候会遇到很多问题,有时候会卸载失败,导致无法重新安装.测试了网上各种办法,删文件,删注册表,重启,360强行删除都不是很有效.最后发现msizap比较有效 ...

  6. redis分片和哨兵

    1 Redis的使用 1.1 Redis入门案例 1.1.1 什么样的数据使用缓存 说明:使用缓存其实为了减少用户查询数据库的时间.如果数据频繁的变更.不适用缓存.缓存中的数据应该保存修改频率不高的数 ...

  7. 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt

    首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ...

  8. C++模板类与Qt信号槽混用

    一.正文 目前正在做一个视频处理相关的项目.项目的技术栈是这样的,UI层采用Qt来实现基本的数据展示和交互,底层音视频采用的是一套基于FFmpeg的视频处理框架.这是一套类似Microsoft Med ...

  9. poj-1031-fence(不是我写的,我只是想看着方便)

    题目大意: 有一个光源位于(0,0)处,一个多边形的围墙.围墙是“全黑”的,不透光也不反射光.距光源r处的光强度为I0=k/r,k为常数. 一块无穷窄高为h的墙上围墙受到的照度为dI=I0*|cosα ...

  10. ubuntu apt-get安装、卸载软件命令及如何查看日志

    linux亮红灯的我,开始学习linux,学习使我快乐,大家一起来学习... 1.安装软件命令 sudo apt-get apache2     安装apache,安装在默认路径下,指定路径安装,其实 ...