使用spring3 @Value访问PropertyPlaceholderConfigurer值? [英] Using spring3 @Value to access PropertyPlaceholderConfigurer values?

查看:200
本文介绍了使用spring3 @Value访问PropertyPlaceholderConfigurer值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的属性源是PropertyPlaceholderConfigurer的子类时,我正在尝试使用@Value在spring bean中设置字符串的值.有人知道该怎么做吗?

I'm trying to set the value of a string in a spring bean using @Value, when my property source is a subclass of PropertyPlaceholderConfigurer. Anyone know how to do this ?

推荐答案

旧问题,但仍然值得回答.您可以使用与原始PropertyPlaceholderConfigurer相同的方式来使用该表达式.

Old question, but still worth to be answered. You can use the expression the same way as you would with the original PropertyPlaceholderConfigurer.

app.properties

app.properties

    app.value=Injected

app-context.xml

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测试了这种方法

Tested this approach using Spring 3.0.6

这篇关于使用spring3 @Value访问PropertyPlaceholderConfigurer值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆