spring异常:Could not resolve placeholder

org.springframework.beans.factory.BeanDefinitionStoreException: 

Invalid bean definition with name '******' defined in null: Could not resolve placeholder 'displayName'

因为你配置了多个 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

这个配置用于 xml 中的占位符,如下:

<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

解决方法:a.xml中配置第一个 PropertyPlaceholderConfigurer 时,将ignoreUnresolvablePlaceholders的值设为true

如下所示:

<bean id="myConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>

 

这个配置告诉spring,当某个placeholder无法找到时,先不要报错,并尝试用另一个PropertyPlaceholderConfigurer来设置placeholder的值。

假设 a.xml 配置了一个 PropertyPlaceholderConfigurer ,并且成功了。

 

后来,b.xml 也配置了一个 PropertyPlaceholderConfigurer ,这时候如果不做特别配置,b.xml 里配置的placeholder将无法使用,并报上面的错误。

如果还不行,将定义PropertyPlaceholderConfigurer 的bean提到applicationContext.xml的最前面

转载于:https://my.oschina.net/u/3676955/blog/1786307

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值