Anotation in Java

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Gopal Naik.

1. @Override

It is a marker annotation that can be used only on methods. A method


annotated with @override must override a method from a superclass. If it
doesn’t, a compile-time error will result It is used to ensure that a superclass
method is actually overridden, and not simply overloaded.

2. @SuppressWarnings

It is used to inform the compiler to suppress specified compiler warnings. The


warnings to suppress are specified by name, in string form. This type of
annotation can be applied to any type of declaration.

3. @SpringBootApplication Annotation

This annotation is used to mark the main class of a Spring Boot application. It
encapsulates @SpringBootConfiguration, @EnableAutoConfiguration,
and @ComponentScan annotations with their default attributes.

4. @SpringBootConfiguration Annotation

It is a class-level annotation that is part of the Spring Boot framework. It implies


that a class provides Spring Boot application configuration. It can be used as an
alternative to Spring’s standard @Configuration annotation so that
configuration can be found automatically. Most Spring Boot Applications use
@SpringBootConfiguration via @SpringBootApplication. If an application uses
@SpringBootApplication, it is already using @SpringBootConfiguration.

5. @EnableAutoConfiguration Annotation
This annotation auto-configures the beans that are present in the class path. It
simplifies the developer’s work by assuming the required beans from the class
path and configure it to run the application.

6. @ComponentScan Annotation

@ComponentScan tells Spring in which packages you have annotated classes


that should be managed by Spring.

7. @Service
We specify a class with @Service to indicate that they’re holding the business
logic. Besides being used in the service layer, there isn’t any other special use
for this annotation. The utility classes can be marked as Service classes.

8. @Repository
We specify a class with @Repository to indicate that they’re dealing with CRUD
operations, usually, it’s used with DAO (Data Access Object) or Repository
implementations that deal with database tables

9. @Controller
We specify a class with @Controller to indicate that they’re front controllers
and responsible to handle user requests and return the appropriate response. It
is mostly used with REST Web Services.

10. @Component
@Component is a class-level annotation. It is used to denote a class as a Component.
We can use @Component across the application to mark the beans as Spring's
managed components. A component is responsible for some operations.
11. @Rest Controller
The @RestController annotation is used to define the RESTful web services. It serves JSON,
XML and custom response

12. @Request Mapping


The @RequestMapping annotation is used to define the Request URI to access the REST
Endpoints.

13. @Request Body


The @RequestBody annotation is used to define the request body content type.

14. @Path Variable


The @PathVariable annotation is used to define the custom or dynamic request URI.

15. @Request Parameter


The @RequestParam annotation is used to read the request parameters from the Request
URL.

16. @GetMapping
@GetMapping get all the data from DB and maps it JSON object.

17. @PostMapping
@PostMapping maps the JSON object content to DB

18. @PutMapping
@PutMapping help us to update data in DB using web-services.

19. @DeleteMapping
@DeleteMapping help us to delete the record in DB using web-services.

20. @Entity
@Entity help us to map the java class with database table

21. @Table
When java class name and database table name are not same then we use it to map

22. @Table
When java class name and database table name are not same then we use it to map

23. @GeneratedValue
@GeneratedValue helps us to auto-increment the value while storing the data in the
database.

24. @Column
When the entity class variable name and the database column name are not same then
this annotation help us to map it.

25. @ModelAttribute
@ModelAttribute maps the form data to entity class object.

26. @Bean
It is a method-level annotation. It is an alternative of XML <bean> tag. It tells the
method to produce a bean to be managed by Spring Container.

27. @ResponseBody
It binds the method return value to the response body. It tells the Spring Boot Framework
to serialize a return an object into JSON and XML format.

28. @RequestAttribute

It binds a method parameter to request attribute. It provides convenient access to the


request attributes from a controller method. With the help of @RequestAttribute
annotation, we can access objects that are populated on the server-side.

You might also like