防止ResourcePropertySource抛出FileNotFoundException

时间:2015-02-03 14:53:58

标签: spring

有没有办法阻止ResourcePropertySource投掷java.io.FileNotFoundException

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="true" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="propertySources">
        <list>
            <bean class="org.springframework.core.io.support.ResourcePropertySource">
                <constructor-arg value="file:#{systemProperties['user.home']}/user.properties"/>
            </bean>
            <bean class="org.springframework.core.io.support.ResourcePropertySource">
                <constructor-arg value="classpath:project.properties"/>
            </bean>
        </list>
    </property>
</bean>

如果project.properties文件未找到,我希望回退到user.properties

1 个答案:

答案 0 :(得分:1)

为什么这么复杂。

<context:property-placeholder location="${user.home}/user.properties,classpath:project.properties" ignore-resource-not-found="true" />

这应该就是你所需要的。不需要EL或直接使用ResourcePropertySource

相关问题