What annotations are included in a Spring Boot application?
The main annotations utilized in Spring Boot applications are as follows:
- @SpringBootApplication is used to identify the main class of a Spring Boot application, it is also a combination annotation that includes the @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations.
- @RestController: Used to mark a class as a Spring MVC controller, handling requests and returning JSON responses.
- @RequestMapping is used to map the URL path of a request to a specific handling method.
- @Autowired is an annotation used for automatically injecting dependency relationships, which can be applied to constructors, setter methods, and properties.
- @Configuration: This annotation is used to identify a class as a configuration class, typically used for configuring beans.
- @EnableAutoConfiguration: Used to start the automatic configuration mechanism of Spring Boot, configuring project classes automatically based on the dependencies of the jar packages.
- @ComponentScan is used to specify the packages that need to be scanned in order to find the classes that need to be automatically wired.
- @Entity: Used to indicate that a class is a JPA entity class.
- @Repository: This annotation is used to identify a class as a repository class in Spring Data, which is used to access a database.
- @Service: Used to identify a class as a service class in the business logic layer.
- @RestControllerAdvice is used to define a global exception handler.
- @RequestMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping are used to define request mapping and HTTP methods.
The above are commonly used annotations in Spring Boot applications, the specific annotations to be used may vary according to the specific business requirements.