4

我想要一些需要的资源,但如果缺少其他资源,请忽略它......怎么做?如我所见,我只能做

<context:property-placeholder
    ignore-resource-not-found="true" 
location="required.properties, not-required-override.properties" />

这会影响那里提到的每个配置。

// 编辑 这是一个工作示例

<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" />
4

2 回答 2

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" />

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

于 2013-09-09T09:14:23.623 回答
0

我想你也可以这样添加:

<context:property-placeholder location="/WEB-INF/properties/config.properties" order="1" ignore-unresolvable="true"/>
于 2016-06-08T06:45:09.077 回答