What is the use of @SpringBootApplication annotation
@SpringBootApplication
It is a core annotation for Spring Boot applications
It is used to tag a main program class to make it the entrance to Spring Boot applications
This annotation is actually a combination annotation
The following three main annotations are included:
-
@SpringBootConfiguration
: This is a special@Configuration
Annotation means that this is a Spring configuration class.@Configuration
Indicates that this class can use Spring IoC containers as the source of bean definition. -
@EnableAutoConfiguration
: This annotation tells Spring Boot to guess and configure the required beans based on the dependencies declared by the application. This allows the context of Spring application to be automatically configured, avoiding a lot of manual configuration. -
@ComponentScan
: This annotation enables component scanning, allowing Spring to find and register all defined in the current package and its subpackages@Component
、@Service
、@Repository
and@Controller
etc components.
The combination of these annotations makes@SpringBootApplication
Become a convenient tool for configuring and launching Spring Boot applications.
Specifically
- Simplify configuration: Through automatic configuration and component scanning, the configuration work of Spring applications has been greatly simplified.
- Convenience: Just add an annotation to the main class to start a complete Spring application.
A typical Spring Boot main program class
As shown below:
import ; import ; @SpringBootApplication public class MySpringBootApplication { public static void main(String[] args) { (, args); } }
In this example:
@SpringBootApplication
AnnotationMySpringBootApplication
Become the entry class to start Spring Boot applications.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.