Spring Boot : Annotations

Spring Boot : Annotations

1. @Controller Annotation

This annotation provides Spring MVC features. It is used to create Controller classes and it handles the HTTP requests.

2. @RequestMapping Annotation

This annotation is used to map the HTTP requests with the handler methods inside the controller class.

3. @RestController Annotation

This annotation is used to handle REST APIs such as GET, PUT, POST, DELETE.

  • @GetMapping: It maps the HTTP GET requests on the specific handler method.
  • @PostMapping:  It is used to create a web service endpoint.
  • @PutMapping: It is used to create a web service endpoint that creates or updates .
  • @DeleteMapping:  It is used to create a web service endpoint that deletes a resource.
  • @PatchMapping: It maps the HTTP PATCH requests on the specific handler method.

4. @RequestParam Annotation

This annotation is basically used to obtain a parameter from URI. @RequestParam annotation is used to read the form data and binds the web request parameter to a specific controller method.

5.@RequestHeader

It is used to get the details about the HTTP request headers.

6.@CrossOrigin

This allows your Spring Boot application to accept requests from different origins (domains), which is necessary when your frontend and backend are hosted on different servers.

7. @PathVariable Annotation

This annotation is used to extract the data from the URI path. It binds the URL template path variable with method variable.

8. @RequestBody Annotation

 It is used to bind HTTP request with an object in a method parameter.

9. @ResponseBody Annotation

This annotation is used to convert the domain object into HTTP request in the form of JSON or any other text. The return type of the method binds with the HTTP response body.

10. @ModelAttribute Annotation

This annotation refers to model object in Spring MVC. It can be used on methods or method arguments as well.

11.@Autowired

 It is used to inject dependencies allowing Spring to automatically inject beans (components, services, repositories) into your classes.

12.@Qualifier

It is used to specify which bean to inject and to resolve the errors that arises when multiple beans of the same type are available in the application.

Read more