Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple properties file in spring

I load a properties file in spring :

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

But if I try to load another file in a different context file I get error.

like image 684
fastcodejava Avatar asked Jun 12 '26 13:06

fastcodejava


2 Answers

According to the sources you must provide comma separated list of propery files resources. This should work for you:

<context:property-placeholder location="classpath:foo1.properties,classpath:foo2.properties"/> 
like image 152
Igor Nikolaev Avatar answered Jun 15 '26 03:06

Igor Nikolaev


if you need to override properties you can do:

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

OR

if the error is due to not finding a certain property, you can set ignoreUnresolvablePlaceholders to true.


OR

if the error is about not found resource ( and you're ok with it ), you can set ignoreResourceNotFound to true.


OR

if there are errors in finding system properties:

The PropertyPlaceholderConfigurer not only looks for properties in the Properties file you specify. By default it also checks against the Java System properties if it cannot find a property in the specified properties files. You can customize this behavior by setting the systemPropertiesMode property of the configurer with one of the following three supported integer values:

never (0): Never check system properties

fallback (1): Check system properties if not resolvable in the specified properties files. This is the default.

override (2): Check system properties first, before trying the specified properties files. This allows system properties to override any other property source.

like image 21
tolitius Avatar answered Jun 15 '26 01:06

tolitius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!