Spring-based annotations

A number of annotations are provided by Spring, which may be categories such as managing life cycle, creating bean instance, wiring annotations, and many more. Let's find them one by one. However, before that, we will need to know one very important thing. The bean definition has to be registered by configuring it in XML. Now, to have annotation-based configuration, the bean registration has to be done using context namespace, as follows:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation= 
"http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd  
 http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd"> 
<context:annotation-config/> 

The <context:annotation-config/> configuration asks the container to consider the annotations on the bean.

Instead of the preceding configuration, one can even go with the following configuration to perform annotation-based configurations:

<bean class="org.springframework.bean.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> 

Once we know how to enable annotations, let's start with using annotations provided by Spring one by one for different scenarios. We will start with Stereotype annotations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.255.36