SpringBootApplication注解说明

📅 2026/7/13 7:10:28 👁️ 阅读次数 📝 编程学习
SpringBootApplication注解说明

SpringBootApplication是组合注解。组合了3个注解:

@SpringBootConfiguration:将该类声明为配置类。

@EnableAutoConfiguration:启用自动配置。

@CompomemtScan:启用组件扫描。

@SpringBootApplication is a convenience annotation that adds all of the following:

  • @Configuration: Tags the class as a source of bean definitions for the application context.
  • @EnableAutoConfiguration: Tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings. For example, if spring-webmvc is on the classpath, this annotation flags the application as a web application and activates key behaviors, such as setting up a DispatcherServlet.
  • @ComponentScan: Tells Spring to look for other components, configurations, and services in the com/example package, letting it find the controllers.