【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 就好了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

OfficialUser

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

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

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

打赏作者

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

抵扣说明:

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

余额充值