Jörn
Jörn

Reputation: 171

Spring: Load additional properties depending on profile

I want to load an additional .properties file with Spring if and only if an additional profile is active. E.g. if profile "foo" is active, I want to load foo.properties. This pseudo code is what I want, assuming "spring.profiles.active=default,foo":

<context:property-placeholder 
location="classpath:component.properties${(spring.profiles.active).contains('foo') ? ',classpath:foo.properties' : ''}" />

Is there a way to do this in Spring?

Upvotes: 2

Views: 214

Answers (1)

Jekin Kalariya
Jekin Kalariya

Reputation: 3507

You can use like this if you are not dealing with multiple profile at same time.

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

Upvotes: 1

Related Questions