Spring context: property-placeholder ignore resources not found

I would like to have the necessary resources, but ignore others if they are not enough ... How to do this? As I see, I can only do

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

Which affects every configuration 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" /> 
+4
source share
2 answers

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

Properties will be merged at runtime, so you can override when the properties file is being read.

+7
source

I think you can also add:

 <context:property-placeholder location="/WEB-INF/properties/config.properties" order="1" ignore-unresolvable="true"/> 
0
source

Source: https://habr.com/ru/post/1501261/


All Articles