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