1.概述
SpringBoot的自动装配,减少了原先需要编写xml配置文件或java配置类。本文将分析SpringBoot自动装配的原理(版本是2.3.5)。从注解的作用到源码分析,再到自定义SpringBoot启动器。
2.自动装配原理分析
自动装配的实现和这个注解有密切的关联。该注解是个复合注解,里面包含了三个关键的注解
- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
本文先介绍@SpringBootConfiguration和@EnableAutoConfiguration两个注解,@