通过Spring按环境注入属性值

时间:2010-03-29 14:23:00

标签: java spring file properties

我有这样的属性文件:

frame.server.dev=mark.is.cool
frame.server.test=chris.is.cool
frame.server.qa=mitch.is.cool
frame.server.prod=cory.is.cool

我需要根据环境注入正确的值。由于我们有一个从环境迁移到环境的ear文件,我需要做这样的事情:

<util:properties id="props" location="classpath:ILog-application.properties"/>

然后:

@Value ("props.frame.server.#{systemProperties.the.environment}")
private String server;

但是,我不能让systemProperties工作,也不能让它在常量之后注入任何东西。有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

应该是

@Value ("#{props['frame.server.' + systemProperties['the.environment']]}")
相关问题