[英]Using spring3 @Value to access PropertyPlaceholderConfigurer values?
当我的属性源是PropertyPlaceholderConfigurer
的子类时,我正在尝试使用@Value
在spring bean中设置字符串的值。 有人知道怎么做吗 ?
老问题,但还是值得回答。 您可以使用与原始PropertyPlaceholderConfigurer
相同的方式使用表达式。
app.properties
app.value=Injected
APP-context.xml中
<bean id="propertyConfigurer" class="MyPropertyPlaceholderConfigurer">
<property name="location">
<value>file:app.properties</value>
</property>
</bean>
在目标bean中
@Value(value="${app.value}")
private String injected;
使用Spring 3.0.6测试了这种方法
您是否通过使用属性语法显式地从bean定义文件中注入值来设法让它工作? 理论上,如果有效,那么你应该能够在@Value
使用相同的表达式。 就此而言,你应该能够使用@Autowired @Qualifier
来做到这一点
我不认为可以在@Value
注释中使用SPEL访问PropertyPlaceHolderConfigurer加载的PropertyPlaceHolderConfigurer
。 这将是伟大的,但据我所知,下一个最好的事情是声明:
<util:properties id="props" location="classpath:xxx/yyy/app.props"/>
它可以指向与PropertyPlaceHolderConfigurer
相同的属性文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.