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配置都加载到容器中去了。
一会再写
本文深入探讨了SpringBoot 2.3.2.RELEASE版本中自动配置的实现机制。通过分析@SpringBootApplication注解,揭示了@EnableAutoConfiguration如何加载所有符合条件的@Configuration配置到Spring容器的过程。
20万+

被折叠的 条评论
为什么被折叠?



