2014-04-02 61 views

回答

0

可能是這個解決方案的一半! Spring可以加載通配符資源。請參閱spring <util:properties /> with wildcards

這樣你能說出你的文件,如:如果存在x和y兩者都是

<bean id = "config" 
    class = "org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name = "locations" 
     value = "classpath*:somefolder/*-config.properties" /> 
</bean> 

x-config.propertiesy-config.properties加載。

0

實際上,有一個選項ignoreResourceNotFound,但它不可用於命名空間組件。您可以直接使用PropertiesFactoryBean

<bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name="locations" value="y.properties, x.properties"/> 
    <property name="ignoreResourceNotFound" value="true"/> 
</bean> 

如果您x.properties不存在,它會被忽略,從y.properties屬性將保持不變。

如果x.properties存在,它包含相同的keysy.properties,它們將覆蓋那些來自y.properties,因爲所有locations分別裝入一個接一個。

相關問題