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
. Any
I don't think it is possible to access properties loaded by PropertyPlaceHolderConfigurer
using SPEL in a @Value
annotation. It would be great, but as far as I know, the next best thing is to declare:
<util:properties id="props" location="classpath:xxx/yyy/app.props"/>
It can point to the same properties file as your 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.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
Have you managed to get it to work by explicitly injecting the value from the bean definition file using the property syntax? In theory, if that works, then you should be able to use the same expression in @Value
. For that matter, you should be able to do it using @Autowired @Qualifier
also