Nicolas Widart
Nicolas Widart

Reputation: 1287

Spring PropertySource based on environment

I would like to use a dynamic placeholder inside the PropertySource value options.

This is in order to have the ability to have one file for each environment which overrides the default one. Just like application.properties and application-dev.properties.

Current setup:

@PropertySource("classpath:ione.properties")

I would like to have something like

@PropertySource("classpath:ione-{optionalEnvName}.properties")

Thus reading the --spring.profiles.active=dev option.

Thanks!

Upvotes: 1

Views: 6600

Answers (1)

Marcin Piela
Marcin Piela

Reputation: 146

Run with:

-Dspring.profiles.active=dev

and then:

@PropertySource("classpath:ione-${spring.profiles.active}.properties")

should work

Upvotes: 4

Related Questions