【问题标题】:Reading from a properties file Spring 3从属性文件中读取 Spring 3
【发布时间】:2011-10-25 06:06:52
【问题描述】:

我已经尝试寻找在 Spring 3 中使用 @Value 批注来使用 Spring EL 从属性文件中读取值的示例,但我没有找到一个好的示例。

这是我见过的一些组成部分来实现这一点,但我不知道所有这些如何协同工作以从属性文件中读取

<util:properties id="ewConfiguration" location="classpath:ew.properties"/>

现在,我如何在我的类中使用它从 ew.properties 文件中检索值以将它们绑定到实例变量?

例如,如果存在一个属性 url=www.google.com

我有

@Configuration 
class AppConfig {

 @Value("???")
 private String url //what do I use in the place of the ??? to bind the value of the url property 
                    // in the properties file to this instance variable ?
}

【问题讨论】:

    标签: spring annotations


    【解决方案1】:

    This example 应该足以让您入门。

    Nutshell 像这样引用属性文件的值:

    @Value("#{ewConfiguration['url']}")
    private String url;
    

    【讨论】:

    • url 现在给出 502 bad gateway
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2013-05-26
    • 2023-02-03
    • 2018-10-27
    • 2020-07-01
    相关资源
    最近更新 更多