Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

spring

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]
like image 566
Czar Avatar asked Oct 15 '14 16:10

Czar


1 Answers

Found it, I can simply use

@PropertySource("classpath:/settings/${env}/database.properties")
like image 111
Czar Avatar answered Sep 28 '22 00:09

Czar