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"/>