解决IllegalArgumentException: Could not resolve placeholder in string value ”${XXXXXX}“;

首先要保证所有加载属性的配置(例如:路径、名称....)都没问题,然后出现该错误的原因可能是web项目中,出现了多个properties为扩展名的文件,然后使用了多个<context:properties-placeholder>去加载每个配置文件 

<context:property-placeholder>提供了加载外在参数的配置,当时默认情况下该标签只能spring出现一份,或者是下述配置情况也会出现上述问题

 

如一个配置文件中使用了

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

而另一处使用了(这里的配置等效第二次使用了<context:property-placeholder>)

<bean id="propertyConfigurer">
          <!--class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
        <property name="locations">-->
            <list>
                <value>classpath:bb.properties</value>
            </list>
        </property>
    </bean>

解决办法:

1、如果一处使用了propertyConfigurer,将其替换为标签<context:property-placeholder>

2、在所有的<context:property-placeholder>中,修改属性配置ignore-unresolvable(默认为false)为true

类似这样:

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

 

ignore-unresolvable:是否忽略解析不到的属性,如果不忽略,找不到将抛出异常 

 

 

解决spring加载多个properties文件的问题

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值