当我的属性源是 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 测试了这种方法
关于spring - 使用 spring3 @Value 访问 PropertyPlaceholderConfigurer 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1741968/