Spring context:property-placeholder 一些坑

今天在配置多配置文件的时候偶然发现如果我使用

 1 <context:property-placeholder location="classpath:filePath.properties"/> 
这个进行多行编写配置文件的时候会出现后面那个文件出现读取不到的问题

1     <context:property-placeholder location="classpath:jdbc.properties"/>
2     <context:property-placeholder location="classpath:filePath.properties"/>

这样会导致后面那个配置文件失效

原因:Spring 只会加载第一个context:property-placeholder配置后面的文件将不会再次进行加载,所以导致后面的文件读取不到

解决办法:

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

加入一个ignore-unresolvable="true"属性,将文件用,隔开就可以了

  

原文地址:https://www.cnblogs.com/lonecloud/p/7010651.html