自动配置(Auto-configuration)是 Spring Boot 的灵魂:它在启动时扫描类路径与已有配置,决定往容器里补哪些 Bean,且补的每一个都能被使用者覆盖。理解它,就能看懂任何 Starter 的行为,也能自己写一个。
1. 入口:@SpringBootApplication
@SpringBootApplication
// 展开后:
// @SpringBootConfiguration → 就是 @Configuration
// @ComponentScan → 扫描当前包及子包
// @EnableAutoConfiguration → 自动配置的开关(关键)
2026/10/11大约 4 分钟