Spring Annotation Based Configuration
Starting from Spring 2.5 it wound up conceivable to arrange the reliance infusion utilizing annotations. So as opposed to utilizing XML to portray a bean wiring, you can move the bean design into the part class itself by utilizing explanations on the important class, strategy, or field declaration.
Annotation infusion is performed before XML infusion. Therefore, the last design will abrogate the previous for properties wired through both approaches.
Annotation wiring isn't turned on in the Spring holder as a matter of course. In this way, before we can utilize comment based wiring, we should empower it in our Spring arrangement record. So consider the accompanying design document in the event that you need to utilize any comment in your Spring application.
<?xml adaptation = "1.0" encoding = "UTF-8"?> <beans xmlns = "http://www.springframework.org/pattern/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/pattern/context" xsi:schemaLocation = "http://www.springframework.org/pattern/beans http://www.springframework.org/pattern/beans/spring-beans-3.0.xsd http://www.springframework.org/pattern/setting http://www.springframework.org/pattern/setting/spring-setting 3.0.xsd"> <context:annotation-config/> <!- - bean definitions go here - > </beans>
Once <context:annotation-config/> is arranged, you can begin commenting on your code to demonstrate that Spring ought to consequently wire esteems into properties, techniques, and constructors. Give us a chance to take a gander at a couple of essential comments to see how they work −
|Sr.No.||Annotation & Description|
The @Required comment applies to bean property setter methods.
The @Autowired comment can apply to bean property setter techniques, non-setter strategies, constructor and properties.
The @Qualifier comment alongside @Autowired can be utilized to expel the disarray by specifiying which careful bean will be wired.
Spring underpins JSR-250 based explanations which incorporate @Resource, @PostConstruct and @PreDestroy annotations.