当前位置:   article > 正文

spring:Could not resolve placeholder ‘XXX‘ in value “${XXX}“_could not resolve placeholder 'oss.accesskeyid' in

could not resolve placeholder 'oss.accesskeyid' in value "${oss.accesskeyid}

1、背景
使用@Value注解从配置文件中读取值时出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个context:property-placeholder的原因。

2、原因
因为spring通过反射机制加载外部资源 <context:property-placeholder location="classpath:XXX.properties"/>
在探测到Spring容器中有一个org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的Bean就会停止对剩余PropertyPlaceholderConfigurer的扫描(Spring 3.1已经使用PropertySourcesPlaceholderConfigurer替代PropertyPlaceholderConfigurer了),所以根据加载的顺序,配置的第二个property-placeholder就被没有被spring加载,所以在使用@Value注入的时候解析不了
2、解决方案

在所有<context:property-placeholder location=“classpath:XXX.properties”/>中加入
ignore-unresolvable="true"可以解决

<context:property-placeholder location="classpath:XXX.properties" ignore-unresolvable="true"/>
  • 1

参考地址:https://blog.csdn.net/linwei_1029/article/details/6873764?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-6873764-blog-89931435.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-6873764-blog-89931435.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=2

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号