14

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]
Czar
  • 1,633
  • 2
  • 17
  • 32

1 Answers1

24

Found it, I can simply use

@PropertySource("classpath:/settings/${env}/database.properties")
Czar
  • 1,633
  • 2
  • 17
  • 32
  • Maven cannot see that ${env} unfortunately, so some other way should be chosen. Maybe Maven conf? Indeed, where is no maven deploy required, it does the trick. – deyvw Oct 20 '16 at 11:45
  • 3
    How is maven related here? This is about Spring resolving a property source based on the command line parameter supplied during application launch. – Czar Oct 21 '16 at 13:05
  • Just wanted to note that this also works for environment variables (System.getenv) – Pphoenix Jul 03 '17 at 12:39