Java Spring Annotation
Posted By : Avaneesh Kumar Verma | 28-Jun-2018
Some common Annotation used in SpringBoot
Annotations are becoming very common in Java EE Application. It was first introduced in Java 1.5 version. Frameworks like Spring, Hibernate and Web Services etc are using lots of Annotation. Every annotation has their specific functionality which delivered in the code. It removes the difficulties of writing code in XML because it is very difficult and time-consuming to do any task using XML. Annotation provides metadata of the program. It can be parsed by using tools like annotation parsing tool or by the compiler.
We can create custom Annotation, It is like creating an interface but the difference is that we replace the interface keyword by @ Interface.
Sample Program for creating a custom Annotation.
package com.example.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Target(ElementType.METHOD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface Functoinality{
String createdBy() default "Atul";
String date();
int rev() default 1;
String info();
}
Some common Annotation used in Spring are as follows:
1. @Autowired: It is used to inject the bean dependency in a particular class. It is Autowire ByType internally. Spring Application starts Spring container made the object of all the bean classes stored it in a container and when we use @Autowired annotation the object created by the container is injected in that class where Autowired Annotation is used. If we are
2.
3. @Controller: This annotation used in Spring MVC framework. This annotation tells Spring container that the particular class acts as Controller in the application. The dispatcher scan that class and find the RequestMapping Annotation to map the Request.
4. @Service: This annotation used in Spring MVC framework. This annotation tells the compiler that the particular class is service class. In general, service class contains the logic and communicate with Dao class.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Avaneesh Kumar Verma
Avaneesh is a Software developer Having Knowledge Java , J2EE ,Data Structure and Algorithm ,SQL.