【问题标题】:Injecting property values via Spring by Environment通过 Spring by Environment 注入属性值
【发布时间】:2011-02-02 01:48:13
【问题描述】:

我有一个这样的属性文件:

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 工作,也不能让它在常量之后注入任何东西。有什么帮助吗?

【问题讨论】:

    标签: java spring file properties


    【解决方案1】:

    应该是

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

    【讨论】:

    • 完美。正是我需要的。如您所知,我在注释和属性方面相当菜鸟。我还没有找到一个很好的教程,它没有假设很多 Spring 知识。谢谢!
    • @silver:#{...} 中的表达式是 Spring 表达式语言,请参阅 static.springsource.org/spring/docs/3.0.x/…
    猜你喜欢
    • 2013-01-15
    • 1970-01-01
    • 2015-02-03
    • 2013-11-14
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    相关资源
    最近更新 更多