Spring Boot Day 4

Learn about annotations

Table of contents

No heading

No headings in the article.

Today on the 4th day of spring boot I learned about some annotations that are following:

In Spring Boot, annotations play a significant role in configuring and customizing various aspects of your application. Here are some commonly used annotations in Spring Boot:

  1. @SpringBootApplication: This annotation is used to mark the main class of a Spring Boot application. It combines three annotations: @Configuration, @EnableAutoConfiguration, and @ComponentScan.

  2. @Controller: It marks a class as a controller component that handles HTTP requests and generates HTTP responses.

  3. @RestController: It is a specialized version of @Controller that combines the @Controller and @ResponseBody annotations. It is commonly used for creating RESTful web services that directly serialize the return value to the HTTP response body.

  4. @RequestMapping: It is used to map HTTP requests to specific methods or classes. It can be applied at the class level to define a base URL mapping, and at the method level to define more specific URL mappings.

  5. @Autowired: It is used for automatic dependency injection. It allows Spring Boot to automatically wire the dependencies of a class, eliminating the need for manual instantiation or lookup.

  6. @Value: It is used to inject values from properties files or environment variables into variables or method arguments.

  7. @Component: It is a generic stereotype annotation used to mark a class as a Spring component, allowing it to be detected and instantiated as a bean.

  8. @Service: It is a specialized version of @Component and is used to mark a class as a service component.

  9. @Repository: It is used to mark a class as a repository component, typically for database access or data persistence.

  10. @Configuration: It is used to indicate that a class declares one or more bean definitions. It is often used in conjunction with @Bean methods.

  11. @EnableAutoConfiguration: It is used to enable Spring Boot's auto-configuration feature, which automatically configures various dependencies and beans based on the classpath and other configuration properties.