Category : Spring Boot | Sub Category : Spring Boot | By Prasad Bonam Last updated: 2023-07-09 06:37:14 Viewed : 608
Spring Boot is a popular framework for building Java applications. It provides a set of annotations that help configure and customize various aspects of your Spring Boot application. Here are some commonly used annotations in Spring Boot:
@SpringBootApplication: This annotation is used to mark the main class of a Spring Boot application. It combines three annotations: @Configuration
, @EnableAutoConfiguration
, and @ComponentScan
.
@RestController: This annotation is used to define a RESTful web service controller. It combines the @Controller
and @ResponseBody
annotations.
@RequestMapping: This annotation is used to map a URL or URI template to a specific method in a controller class. It specifies the HTTP request method and the path for handling the request.
@GetMapping, @PostMapping, @PutMapping, @DeleteMapping: These annotations are shortcuts for @RequestMapping
with the respective HTTP methods: GET, POST, PUT, and DELETE.
@PathVariable: This annotation is used to bind a method parameter to a path variable in the URL.
@RequestParam: This annotation is used to bind a method parameter to a request parameter in the URL query string.
@RequestBody: This annotation is used to bind the request body to a method parameter in the controller method.
@Autowired: This annotation is used to automatically wire dependencies by type. It can be applied to constructors, fields, or setter methods.
@Qualifier: This annotation is used along with @Autowired
to specify the name or identifier of a bean when multiple beans of the same type exist.
@Component, @Service, @Repository: These annotations are used to mark a class as a Spring-managed component, service, or repository, respectively.
@Configuration: This annotation is used to indicate that a class provides bean definitions. It is often used in combination with @Bean
methods to define beans.
@EnableAutoConfiguration: This annotation enables Spring Boots auto-configuration feature, which automatically configures the application based on the classpath and other conditions.
@Conditional: This annotation is used to conditionally activate or deactivate a bean or a configuration based on specific conditions.
@Value: This annotation is used to inject values from external properties files or environment variables into a beans properties.
@EnableSwagger2: This annotation enables Swagger documentation for RESTful APIs in your Spring Boot application.
These are just a few examples of the many annotations provided by Spring Boot. Each annotation serves a specific purpose and helps in configuring different aspects of your application. You can explore the Spring Boot documentation to learn more about these annotations and their usage.