vendredi 27 février 2015

Spring @Value annotation and setter injection difference

when set value to object from property file use @Value annotation some kind of value like below not set fine but use setter injection work fine.


my properties file like this.



app.work.dir=file:${user.home}/WORK


class file like below.



@Value("#{configProperties['app.work.dir']}")
private String workdir;


and this is my xml setting.



<util:properties id="configProperties" location="classpath:config.properties" />


when use setter injection like below then work fine.



<bean id="sampleService" class="aaa.SampleService">
<property name="workdir" value="${app.work.dir}" />
</bean>


i'm not sure why and if possible i want to use @Value annotation.


Aucun commentaire:

Enregistrer un commentaire