Using the STS Eclipse plugin for a Spring Template project for a Hibernate utility (using Spring 3.1), there is some code generated that I believe is injecting a bean vs. a value:
@Configuration
public class HibernateConfiguration {
So then what exactly is @Value for. Well it is for Spring Expression Language. And in the Spring Expression language it can evaluate to anything, any type.
So yes, the evaluation of @Value("#dataSource") is the bean with the id called dataSource, and that it what it was evaluated to the ref of the bean or the DataSource itself and the instance variable is set to that value.
Les Hartzman wrote:Thanks for the response. The places where I've seen @Value used for strings has typically been when there is a properties file involved:
@Value(${jdbc.url})
private String jdbcUrl;
Could @Inject or @Autowired have been used in place as well?
Les
In this particular case, no. In the dataSource case way above, yeah. I probably would have chosed @Autowired or @Inject instead. You could partially argue that with @Value is like @Autowired with @Qualifier without it being 2 annotations, now it is just one.