2014-04-02 62 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分别装入一个接一个。

相关问题