Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring context:property-placeholder ignore resources not found

I'd like to have some resources required but ignore other one if its missing... How to do that? As I see it I can only do

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

Which affects every config listed mentioned there.

// EDIT This is a working example

<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" />
like image 236
kboom Avatar asked Jan 12 '23 10:01

kboom


1 Answers

Add a PropertiesFactoryBean element for the required dependencies and simply wire the properties to the <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" />

The properties will me merged at runtime so you can still override when a properties file is read.

like image 89
M. Deinum Avatar answered Jan 31 '23 11:01

M. Deinum