我必须用春天util:properties
,但是,我需要的是这样的:如何在util:属性中使用属性文件?
if propertyFile x exists, use x, otherwise, use y.
能否请您指教我怎样才能获得呢?
我必须用春天util:properties
,但是,我需要的是这样的:如何在util:属性中使用属性文件?
if propertyFile x exists, use x, otherwise, use y.
能否请您指教我怎样才能获得呢?
可能是这个解决方案的一半! 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.properties和y-config.properties加载。
实际上,有一个选项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
存在,它包含相同的keys
为y.properties
,它们将覆盖那些来自y.properties
,因为所有locations
分别装入一个接一个。