如何使用系统环境变量作为@PropertySource值的一部分?

时间:2022-03-22 22:41:54

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

我想用java启动我的程序... -Denv = prod ...并且有

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

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

读取属性文件:/settings/prod/database.properties

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

我尝试过使用#{systemProperties ['env']}但是没有解决异常:

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

1 个解决方案

#1


9  

Found it, I can simply use

找到它,我可以简单地使用

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

#1


9  

Found it, I can simply use

找到它,我可以简单地使用

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