Spring上下文:property-placeholder忽略未找到的资源

kbo*_*oom 4 spring config properties

我想要一些资源但是如果遗失了就忽略了其他资源......如何做到这一点?我认为我只能这样做

<context:property-placeholder
    ignore-resource-not-found="true" 
location="required.properties, not-required-override.properties" />
Run Code Online (Sandbox Code Playgroud)

这会影响那里列出的每个配置.

//编辑这是一个有效的例子

<bean id="requiredProperties"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>classpath:database.properties</value>
            <value>classpath:storage.properties</value>
            <value>classpath:log4j.properties</value>
            <value>classpath:mailing.properties</value>
        </list>
    </property>
</bean>

<context:property-placeholder
    properties-ref="requiredProperties" ignore-resource-not-found="true"
    location="file:\${user.dir}/config/cvnizer.properties" />
Run Code Online (Sandbox Code Playgroud)

M. *_*num 9

PropertiesFactoryBean为所需的依赖项添加元素,并简单地将属性连接到<context:property-placeholder />.

<bean id="requiredProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations" value="classpath:file1.properties,classpath:file2.properties" />
</bean>

<context:property-placeholder properties-ref="requiredProperties" ignore-resource-not-found="true" location="not-required-override.properties" />
Run Code Online (Sandbox Code Playgroud)

这些属性将在运行时合并,因此您仍可以在读取属性文件时进行覆盖.