【Spring 中: Could not resolve placeholder ‘xxx‘ in value “ ${xxx}“】

Spring :Could not resolve placeholder ‘xxx’ in value " ${xxx}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘xxx’ in value " ${xxx}"

先来看一下整个流程:

  1. 在.xml文件头加入
xmlns:context="http://www.springframework.org/schema/context"

但是仅仅写个这是不行的会报错
还需在最后面加入两个地址:

http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
  1. 在配置文件.xml中引入xxx.properties文件;加载配置文件
 <context:property-placeholder location="classpath: *.properties" />
  1. 在bean里面调用xxx.properties文件里面的属性键
<bean id="userDao" class="com.qwe.Dao.Imp.UserDaoImp">
        <property name="userName" value="${username}"/>
        <property name="password" value="${password}"/>
</bean>

现在就可以运行了
然后就可能会出现:
在这里插入图片描述
经过查阅以及尝试之下找出了办法:
尝试把

<context:property-placeholder location="classpath:*.properties" />

变为具体的文件名

<context:property-placeholder location="classpath:data.properties"/>

还有另一种情况的话是在后面加上 ignore-unresolvable=“true”

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

我本人是属于第一种情况把 *.properties 改为具体文件名 data.properties 就好了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

OfficialUser

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

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

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

打赏作者

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

抵扣说明:

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

余额充值