Spring Annotations allow us to configure dependencies and implement dependency injection through java programs. In this post, I will list down the Spring annotations that you will use in everyday day-to-day development with examples.

Spring-Security-Tutorial-1
Examples


Following are the Spring annotations, there is no particular order, you can pick any of the annotations which you want to know.

1. @PathVariable:

This annotation is used to pass the data from client to server inside the URI. We will create a spring boot project step-by-step and pass the data from client to server. Follow this tutorial to understand more.

2. @RequestParam:

This annotation is also used to pass the data from client to server using query params. We will create a spring boot project step-by-step and pass the data from client to server. Follow this tutorial to understand more.

3. @RequestBody:

This annotation is used to receive the JSON payload from the HTTP request body. We will create a spring boot project step-by-step and receive the JSON payload from the HTTP request.

4. @ResponseBody:

This annotation is used to send the HTTP response back to the client. We will create a spring boot project step-by-step and send the HTTP response back to the client

5. @RequestMapping:

This annotation is used to map the HTTP requests to the handler methods in the controller. We will create a spring boot project step-by-step and map the HTTP requests to the handler methods.

6. @Autowire:

This annotation is used to inject the dependencies without creating an object using a new keyword. We will create a spring boot project step-by-step and inject the dependencies without creating an actual object.

7. @Bean:

This annotation is used to create a bean by spring framework itself. We will create a spring boot project step-by-step and configure the spring boot app to create a bean.

8. @ExceptionHandler:

This annotation is used to handle exceptions at the class level. We will create a spring boot project step-by-step and handle the exceptions at the class level.

9. @ControllerAdvice:

This annotation is used to handle exceptions at the global level. We will create a spring boot project step-by-step and handle the exceptions at the global level.

10. @Valid:

This annotation is used to validate the bean. We will create a spring boot project step-by-step and validate the bean.

11. @PostConstruct:

This annotation is executed after injections are committed to the given bean. We will create a spring boot project step-by-step and we will discuss this annotation.

12. @ResponseStatus:

This annotation is used to return the HTTP status to the client. We will create a spring boot project step-by-step and return the HTTP status to the client.

13. @ModelAttribute:

This annotation is used to access the model class data. We will create a spring boot project step-by-step and access the model class data with this annotation.

14. @RequestHeader:

This annotation is used to receive the HTTP header values. We will create a spring boot project step-by-step and receive the HTTP header values.

15. @Controller:

This annotation is used to mark the java class as a Controller class. We will create a spring boot project step-by-step and create a controller class.

16. @RestController:

This annotation is used to mark the java class as the Rest controller class. We will create a spring boot project step-by-step and create a rest controller class.

17. @Value:

This annotation is used to read the property value from the property file. We will create a spring boot project step-by-step and read the property from the property file with this annotation.

More coming soon… Keep an eye on this post. 🙂