spring:Could not resolve placeholder ‘XXX‘ in value “${XXX}“

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"/>

参考地址: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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
引用中提到的异常是"java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.mail.username' in value "${spring.mail.username}"。这个异常通常是因为在Spring应用程序中无法解析配置文件中的占位符。占位符通常用于在配置文件中引用其他属性或环境变量的值。如果无法找到对应的占位符值,就会抛出这个异常。 引用中提到的异常是"Caused by: java.lang.IllegalArgumentException: input == null!"。这个异常通常是由于尝试读取一个空值图片而引起的。在ImageIO类的read()方法中,如果传入的图片参数为null,则会抛出这个异常。 引用中提到,出现这种问题通常是因为没有正确加载配置文件导致的。比如,可能没有正确配置application.yml或者application.properties文件,导致Spring无法读取配置文件中的数据,进而无法使用@Value注解来初始化数据。 综上所述,java.lang.IllegalArgumentException: Could not resolve placeholder异常可能是由于未解析配置文件中的占位符所导致的,而java.lang.IllegalArgumentException: input == null!异常可能是由于尝试读取空值图片而引起的。为了解决这些异常,可以检查配置文件是否正确加载并且占位符是否正确解析,同时确保传递给ImageIO的图片参数不为空。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [解决java.lang.IllegalArgumentException: Could not resolve placeholderxxx‘ in value “${xxx}...](https://blog.csdn.net/lvoelife/article/details/126404938)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [java.lang.IllegalArgumentException:Input == null的异常处理](https://download.csdn.net/download/weixin_38645373/14043809)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十一*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值