Spring容器采用反射掃描的發(fā)現(xiàn)機(jī)制,在探測到Spring容器中有一個 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的 Bean就會停止對剩余PropertyPlaceholderConfigurer的掃描(Spring 3.1已經(jīng)使用PropertySourcesPlaceholderConfigurer替代 PropertyPlaceholderConfigurer了)缅疟。
換句話說,即Spring容器僅允許最多定義一個PropertyPlaceholderConfigurer(或)变姨,其余的會被Spring忽略掉寺渗。
拿上來的例子來說大猛,如果A和B模塊是單獨運(yùn)行的,由于Spring容器都只有一個PropertyPlaceholderConfigurer诅需, 因此屬性文件會被正常加載并替換掉漾唉。如果A和B兩模塊集成后運(yùn)行,Spring容器中就有兩個 PropertyPlaceholderConfigurer Bean了堰塌,這時就看誰先誰后了赵刑, 先的保留,后的忽略蔫仙!因此料睛,只加載到了一個屬性文件,因而造成無法正確進(jìn)行屬性替換的問題摇邦。
使用spring提供的通配符就OK了
<context:property-placeholder location="classpath*:*.properties"/>