spring boot版本:2.3.2.RELEASE
在入口类我们使用了@SpringBootApplication注解,点击进去我们就会发现有这样的代码
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration ----->这个就是帮助我们进行自动配置的注解
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
点击进去我们就会发现有如下的代码
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
我们需要知到:spring boot借助@Import(AutoConfigurationImportSelector.class)一句话,把所有符合条件的@Configuration配置都加载到容器中去了。
一会再写