I would really like to annotate a method with a reference to a single property in a property file for injection.
@Resource('${my.service.url}') private String myServiceUrl;
Of course, this syntax does not work 😉 Thats why I’m asking here.
I am aware that I can inject the full properties file, but that just seems excessive, I dont want the property file – I want the configured value.
Edit: I can only see PropertyPlaceholderConfigurer examples where XML is used to wire the property to the given field. I still cannot figure out how this can be achieved with an annotation ?
There’s a thread about this on the Spring forum. The short answer is that there’s really no way to inject a single property using annotations.
I’ve heard that the support for using annotations will be improved in Spring 3.0, so it’s likely this will be addressed soon.