@Autowired
Spring 2.5 introduces @Autowired annotations that allow you to annotate class member variables , methods , and constructors , and complete the task of automating assembly . Use the @Autowired to eliminate the set, get method .
Add to the member variable to omit the Get set method.
But first, you have to configure Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in the spring configuration file now.
@Resource Annotations are used to activate the dependency injection of a named resource (named Resource), which is typically converted to an object that is bound to a Jndi context in a Java EE application. Spring does support using @Resource to parse objects through Jndi lookup, by default, with a "bean name" that matches the name provided by the @Resource annotation The spring management object will be injected.
@Resource (name= "DataSource")
Public void Setdatasource (DataSource DataSource) {
this. DataSource = DataSource;
}
Spring passes a reference to the annotated setter method to the spring management object named "DataSource" by the bean.
Private DataSource DataSource;
@Resource
Public void Setdatasource (DataSource DataSource) {
this. DataSource = DataSource;
}
It is also possible to use @Resource annotations directly on a field (field). By not exposing the setter method, the code becomes more compact and provides additional benefits that the domain cannot modify. As will be shown below,@Resource annotations do not even require an explicit string value, and if no value is provided, the domain name will be treated as a default value.
@Resource
Private DataSource DataSource; //Inject the bean named ' DataSource '
Spring annotation resolves auto-injection in attributes