2012-11-21 51 views
0

如何在以下两种情况下使用@Value?背景:财产持有人比。 PropertyPlaceholderConfigurer

案例1:我定义为提供一个PropertyPlaceholderConfigurer豆如下

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <value>file:#{ systemProperties['user.home']}/myconf/settings.properties</value> 
    </property> 
</bean> 

案例2:我没有定义bean,但我已经宣布财产占位符在上下文如下

<context:property-placeholder 
    location="file:#{ systemProperties['user.home']}/myconf/settings.properties" /> 

回答

0

在这两种情况下,你会使用像

@Value(value="${key.in.file}") 
private String myVar;