Spring :Could not resolve placeholder ‘xxx’ in value " ${xxx}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘xxx’ in value " ${xxx}"
先来看一下整个流程:
- 在.xml文件头加入
xmlns:context="http://www.springframework.org/schema/context"
但是仅仅写个这是不行的会报错
还需在最后面加入两个地址:
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
- 在配置文件.xml中引入xxx.properties文件;加载配置文件
<context:property-placeholder location="classpath: *.properties" />
- 在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 就好了。