Spring Configuration Based on Annotation
by, 07-07-2012 at 06:25 PM (1032 Views)
The dependency injection can be configured using annotations in Spring 2.5 and above. The configuration of bean class can be done in class itself as compared to XML based bean wiring with the use of annotations on relevant method, class or field declaration.
The XML injection is performed after the annotation based injection so the XML injection will override the annotation injection.
The Spring container will not turn on the annotation wiring by default. So you will need to enable annotation based wiring before using it.
After configuring annotation, it is allowed to annotate you code so that Spring can attach values into properties automatically.
Following are the important annotations and its working:
• @Required: This annotation is applied to setter methods of the bean.
• @Autowired: This annotation is applied to non setter methods, setter methods, properties and constructor.
• Qualifier: It will remove the confusion of using exact bean with the help of @Autowired annotation.