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"属性,将文件用,隔开就可以了

  


免责声明!

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



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