spring配置文件中context:property-placeholder導入多個獨立的配置文件


spring中 context:property-placeholder 導入多個獨立的 .properties配置文件?

Spring容器采用反射掃描的發現機制,在探測到Spring容器中有一個 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的 Bean就會停止對剩余PropertyPlaceholderConfigurer的掃描(Spring 3.1已經使用PropertySourcesPlaceholderConfigurer替代 PropertyPlaceholderConfigurer了)。

換句話說,即Spring容器僅允許最多定義一個PropertyPlaceholderConfigurer(或<context:property-placeholder/>),其余的會被Spring忽略掉(其實Spring如果提供一個警告就好了)

舉個例子,applicationContext.xml文件中需要導入jdbc.properties和redis.properties兩個配置文件,

那這樣寫是不行的,只能識別到jdbc.properties

<context:property-placeholder location="classpath:jdbc.properties" />
<context:property-placeholder location="classpath:redis.properties" />

咋解決呢?

通配符解決

<context:property-placeholder location="classpath*:conf/conf*.properties"/>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM