很多Spring Boot开发者总是在主类上添加@Configuration、@EnableAutoConfiguration和@ComponentScan。因为这些注解经常一起使用,Spring Boot提供了一个方便的替代方案:@SpringBootApplication。

@SpringBootApplication注解等价于同时使用默认配置的@Configuration、@EnableAutoConfiguration和@ComponentScan:

注:@SpringBootApplication还提供了定制@EnableAutoConfiguration和@ComponentScan属性的别名。