Czar
Czar

Reputation: 1693

How to use system environment variable as part of @PropertySource value?

I want to launch my program with java ... -Denv=prod ... and have

@PropertySource("classpath:/settings/$idontknowwhat$/database.properties")`

read properties file: /settings/prod/database.properties

I have tried using #{systemProperties['env']} but it is not resolved with exception:

Could not open ServletContext resource ['classpath:/settings/#{systemProperties['env']}/database.properties]

Upvotes: 14

Views: 17463

Answers (1)

Czar
Czar

Reputation: 1693

Found it, I can simply use

@PropertySource("classpath:/settings/${env}/database.properties")

Upvotes: 24

Related Questions