- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan
1、@SpringBootConfiguration
@SpringBootConfiguration的作用就是将当前类申明为配置类,同时还可以使用@bean注解将类以方法的形式实例化到spring容器,而方法名就是实例名。
1.3 @ComponentScan
@ComponentScan作用就是扫描当前包以及子包,将有@Component,@Controller,@Service,@Repository等注解的类注册到容器中,以便调用。
如果@ComponentScan不指定basePackages,那么默认扫描当前包以及其子包,而@SpringBootApplication里的@ComponentScan就是默认扫描,所以我们一般都是把springboot启动类放在最外层,以便扫描所有的类。
1.4 @EnableAutoConfiguration
@EnableAutoConfiguration主要就是通过内部的方法,扫描classpath的META-INF/spring.factories配置文件(key-value),将其中的org.springframework.boot.autoconfigure.EnableAutoConfiguration 对应的配置项实例化并且注册到spring容器。