2011-10-25 108 views
1

我试过寻找一个在Spring 3中使用@Value注释从属性文件中使用Spring EL读值的例子,但我还没有找到一个好例子。从属性文件读取Spring 3

下面是一些构成件我已经看到了实现这一目标,除了我不知道该怎么所有这些一起工作来读取属性文件

<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 ? 
} 

回答

4

This example应该足以让你开始。

果壳参考属性文件中的值是这样的:

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

网址现在给502网关 – Tommy