Overriding properties file with spring

I have the following properties file defined in one of my Spring (3.1) XML files:

<context:property-placeholder location="classpath:MyConfigFile.properties"/> 

I want to define a second file optional , which will override the file "MyConfigFile.properties" and load instead.

In other words, I want my application to download the file "MyConfigFile.properties", but if "StrogerConfigFile.properties" is available in the class path, it will be downloaded.

Does anyone know how this can be done using Spring XML?

+4
source share
2 answers
 <context:property-placeholder location="file:///[path]/override1.properties, file:///[path]/override2.properties" properties-ref="defaultProps" /> <bean id="defaultProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <array> <value>classpath:default1.properties</value> <value>classpath:default2.properties</value> </array> </property> <property name="properties"> <util:properties local-override="true"> <prop key="some.property">some value</prop> </util:properties> </property> </bean> 

This setting I'm using is quite flexible. Allows you to get the basic default values ​​directly in xml, by default in the properties file and overrides in another properties file.

+13
source

You tried

 <property name="ignoreResourceNotFound" value="true"/> <property name="locations"> <list> <value>classpath:default.properties</value> <value>classpath:overwrite.properties</value> </list> </property> 
+1
source

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


All Articles