$Value{}ntException: Could not resolve placeholder 'KEY' in string value "${

springmvc 中@Value("${KEY}")  出现 $Value{}ntException: Could not resolve placeholder 'KEY' in string value "${

 错误。

 


down vote

Don't use multiple <context:property-placeholder/> tags, refer below code for the same and also make sure you have a key "com.ibm.CORBA.securityServerHost" with a value in either of your property file.


<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location">
      <list>
         <value>classpath:em-management.properties</value>
         <value>file:///opt/ass/swp/conf/platform.properties</value>
      </list>
   </property>
   <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

 

错误原因: 我在applicationContext-dao.xml和 redis-config.xml分别用了扫描器

<context:property-placeholder location="classpath:config/redis.properties"/>
如果再在这两个文件里扔一个扫描constant目录下属性文件的扫描器 那么同时存在两个:
此时要加上
ignore-unresolvable="true"

 

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

 

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


 

 

 

我又在applicationContext-service.xml 中又加载了一个属性文件
<bean id="appProperty"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:constant/constant.properties</value> </list> </property> </bean>  发现这个文件在我使用的时候@Value("${KEY}") 所注入的值直接是引号里面的 “${KEY}”,所以没有任何效果。
 
如果上面代码配置在springmvc文件中有效,且如果换成下面配置也有效, 
 
 
<context:property-placeholder location="classpath:constant/constant.properties" ignore-unresolvable="true"/>


也就是说我不在同一个文件中使用<context:property-placeholder就不需要添加

ignore-unresolvable="true"

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值