1.@SpringBootApplication

是SpringBoot的最核心的注解,在SpringBoot的主类上,标识是SpringBoot应用,用来开启SpringBoot的各项能力。由@SpringBootConfiguration @EnableAutoConfiguration @ComponentScan 三个注解组成。这三个注解是一起使用,所以SpringBoot提供了一个统一的注解@SpringBootApplication

2.@EnableAutoConfiguration

允许SpringBoot自动装配,开启改注解,SpringBoot能根据当前类路径下的包或者类来配置Spring Bean。@EnableAutoConfiguration实现的关键在于引入了AutoConfigurationImportantSelector,其核心逻辑为selectImports方法,从配置文件MATA-INF/spring.factories加载所有可能用到的自动装配类;exclude excludeName 属性携带的类排除;过滤,将满足条件@Conditional的自动配置类返回。

3.@SpringBootConfiguration

改注解就是@Configuration注解的变体,用来修改SpringBoot配置。

4.@ComponentScan

常用的注解@Controller @Service @Repository,有一个共同的注解@Component,@ComponentScan 标注的就会扫描这些注解标注的类到Spring容器中

举报/反馈
专注JAVA设计 每天分享行业深度经验
关注
0
0
收藏
分享