Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple property-placeholder in a Spring xml file

Tags:

java

spring

I have a question related to how Spring handles multiple property-placeholder.

I have this section of code:

<context:property-placeholder location="classpath:dir1/${myapp.system.property}.properties"/>

The property myapp.system.property is a defined System property.

If it is defined to "devsystem", for example, all the properties defined in devsystem.properties are imported and are available to use in the code below.

Now I wanted to have another property file whose name is defined by a properties in the devsystem.property file:

<context:property-placeholder location="classpath:dir1/${myapp.system.property}.properties"/>
<context:property-placeholder location="classpath:dir2/myapp-${myapp.environment}.properties"/>

myapp.environment is a property defined in the devsystem.properties file.

This stopped working. Spring cannot resolve ${myapp.environment} and complains it cannot locate file dir2/myapp-${myapp.environment}.properties.

Can someone let me know what I did wrong and how can I make this working?

like image 661
Kevin Avatar asked Feb 11 '23 16:02

Kevin


1 Answers

You can do something like this

<context:property-placeholder location="classpath:file1.properties,classpath*:project-common.properties,classpath*:project-${spring.profiles.active}.properties"/>

In my case, it was a legacy system so property files didn't have some standard names but for sure you can use wildcards to reference your property files.

<context:property-placeholder location="classpath:*.properties"/>
like image 79
Desorder Avatar answered Feb 14 '23 06:02

Desorder