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/setting/spring-setting 3.0.xsd"> 


<!- - bean definitions go here - > 


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
1 @Required

The @Required comment applies to bean property setter methods.

2 @Autowired

The @Autowired comment can apply to bean property setter techniques, non-setter strategies, constructor and properties.

3 @Qualifier

The @Qualifier comment alongside @Autowired can be utilized to expel the disarray by specifiying which careful bean will be wired.

4 JSR-250 Annotations

Spring underpins JSR-250 based explanations which incorporate @Resource, @PostConstruct and @PreDestroy annotations.

© Javacodegeeks 2018 -2019
All Right Reserved and you agree to have read and accepted our term and condition.

Python 3