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. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command ' finished with non-zero exit value 1

    Error:Execution failed for task ':lenovoAlbum:processReleaseResources'. > com.android.ide.common. ...

  2. struts自定义拦截器配置

    配置自己的拦截器可以先参照下系统的拦截器是怎么配置的,首先打开struts-default.xml搜索下interceptor:系统里的拦截器有很多,拦截器都是放在堆栈里的,系统引用的是默认堆栈, & ...

  3. c#中事物使用

    数据库事务(简称: 事务)是数据库管理系统执行过程中的一个逻辑单位,由一个有限的数据库操作序列构成.当事务被提交给了DBMS(数据库管理系统),则DBMS(数据库管理系统)需要确保该事务中的所有操作都 ...

  4. 夺命雷公狗-----React_native---4---初始化项目

    我们首先在android目录下创建一个apps的文件夹: 然后我们在apps目录下,按住shift键加鼠标右键选择--在此打开命令窗口输入命令初始化项目 然后就是等了................. ...

  5. 夺命雷公狗-----React---26--小案例之react经典案例todos(统计部分的完成)

    这一个其实是比较容易的,只需要统计他的总数和已完成的即可, 效果如下所示: 代码如下所示: <!DOCTYPE html> <html lang="en"> ...

  6. C#中try catch中throw ex和throw方式抛出异常有何不同

    我们在C#的try catch代码块中里面经常使用throw语句抛出捕捉到的异常,但是你知道吗使用throw ex和throw抛出捕获到的异常效果是不一样的. 异常捕捉的原理 首先先介绍一下C#异常捕 ...

  7. OSI Model

  8. Mono.Ceil 无法保存Silverlight 程序集

    一句话: 处理Silverlight程序集之前, 须先移除强名称(StrongNameRemoveHelper), 之后Reflexil 即可一如预期的正常工作.

  9. 使用tmpfs作为缓存加速缓存的文件目录

    使用tmpfs作为缓存加速缓存的文件目录 [root@web02 ~]# mount -t tmpfs tmpfs /dev/shm -o size=256m[root@web02 ~]# mount ...

  10. 鸟哥的linux私房菜学习记录之软件安装原始码与Tarball