Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spring3 @Value to access PropertyPlaceholderConfigurer values?

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 ?

like image 704
krosenvold Avatar asked Nov 16 '09 12:11

krosenvold


1 Answers

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.value=Injected

app-context.xml

    <bean id="propertyConfigurer" class="MyPropertyPlaceholderConfigurer">
      <property name="location">
        <value>file:app.properties</value>
      </property>
    </bean>

in the target bean

    @Value(value="${app.value}")
    private String injected;

Tested this approach using Spring 3.0.6

like image 199
micfra Avatar answered Nov 07 '22 19:11

micfra