java.lang.IllegalArgumentException: Could not resolve placeholder 'XXX' in string value "${XXX}"


错误产生原因:

在Spring的配置文件中配置了多个<context:property-placeholder>标签

1、什么是<context:property-placeholder >:

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

2、<context:property-placeholder >的用途:

本地文件:

 在Spring的配置文件中配置:

3、使用:

1).在配置文件中使用

 2).在Java代码中使用(先引入,后使用)

然后就可以在需要该参数的地方使用了。

错误产生的根本原因:

        Spring容器是采用反射扫描的发现机制,通过标签的命名空间实例化实例,当Spring探测到容器中有一个org.springframework.beans.factory.config.PropertyPlaceholderCVonfigurer的Bean就会停

对剩余PropertyPlaceholderConfigurer的扫描,即只能存在一个实例!然后你在其它地方引用你配置的第二个<context:property-placeholder>中的值就会报错。

解决方案

1.将多个配置文件合并为一个

配置:

2.更改配置:

在每一个<context:property-placeholder>标签后面都加上 ignore-unresolvable="true" 

3.更改配置:

location可以包含多个文件,之间用逗号分隔

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM