解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"

本文探讨了在Spring配置文件中使用<context:property-placeholder>标签的问题,特别是当出现重复配置时如何解决。提供了两种解决方案,并解释了ignore-unresolvable属性的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<context:property-placeholder>标签提供了一种优雅的外在化参数配置的方式,不过该标签在spring配置文件中只能存在一份!


导致这一问题的原因:使用了重复的property-placeholder

如一个配置文件中使用了

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

而另一处使用了

<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. 两处都添加ignore-unresolvable="true"

配置文件1:

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

配置文件2:

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

 

解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"

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




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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值