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

错误产生原因:

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

什么是<context:property-placeholder >:

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

<context:property-placeholder >的用途:

本地文件:

在Spring的配置文件中配置:


使用:

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可以包含多个文件,之间用逗号分隔



猜你喜欢

转载自blog.csdn.net/qq_39056805/article/details/80586672
今日推荐