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

2022-09-04 01:32:48

我想启动我的程序java ... -Denv=prod ...

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

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

我尝试过使用,但未解决,但有例外:#{systemProperties['env']}

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

答案 1

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

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

答案 2

推荐