Java异常 - java.lang.IllegalArgumentException: Could not resolve placeholder 'xxxx' in string value xx

版权声明:写文章辛苦,请不要复制粘贴,如果要,请注明来处 https://blog.csdn.net/u012627861/article/details/84639319

异常描述

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'xxx' defined in URL[file:/xxxx/xxx.xml]: Could not resolve place holder 'xxx' in string value 'xxx': nexted exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'xxxx' in string value 'xxx'
项目中引入了外部的properties文件,如application.properties等。检查了properties中的属性的确存在,属性名称在代码和properties中保持一致,但始终出现该错误。

异常分析

如果仔细检查后发现properties中定义的属性名称和代码中保持一致,那么说明properties没有被解析或者解析失败了,总之问题出在properties上,如下:

  1. properties压根没被引入,比如两个properties只引入了其中一个
  2. properties引入后压根就没正确解析

根据以上情况进行排查。

排查

  1. 是否存在多个context:property-placeholder,在spring中只会使第一个生效,其后的被忽略,如果需要配置多个properties,在location中使用逗号隔开即可。如location="classpath:xxx1.properties,classpath:xxx2.properties"
  2. 尝试在properties文件的首行空出一行,然后启动项目看是否能正确读取文件。如果能,说明properties的内部结构发生了改变。这可能是通过会自动改变文件编码(或其它影响文件内部结构的属性)的编辑器如windows记事本、WinSCP自带编辑器等编辑过

(完)

猜你喜欢

转载自blog.csdn.net/u012627861/article/details/84639319