“Spring Boot 自动配置图示”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) 小 (Jihongchang移动页面Spring Boot 加载自动配置至Spring Boot 自动配置图示) |
||
(未显示同一用户的5个中间版本) | |||
第1行: | 第1行: | ||
{| class="wikitable" | {| class="wikitable" | ||
− | |@SpringBootApplication | + | ! colspan="7" |@SpringBootApplication |
|- | |- | ||
+ | |@SpringBootConfiguration | ||
+ | ! colspan="5" |@EnableAutoConfiguration | ||
+ | |@ComponentScan(excludeFilters = { | ||
+ | @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), | ||
+ | |||
+ | @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) | ||
+ | |||
+ | }) | ||
+ | |- | ||
+ | |@Configuration | ||
+ | ! colspan="4" |@AutoConfigurationPackage | ||
+ | |@Import(AutoConfigurationImportSelector.class) | ||
| | | | ||
|- | |- | ||
+ | | | ||
+ | |@Retention(RetentionPolicy.RUNTIME) | ||
+ | |@Documented | ||
+ | |@Inherited | ||
+ | |//给容器中导入一个组件 | ||
+ | |||
+ | @Import(AutoConfigurationPackages.Registrar.class) | ||
+ | |AutoConfigurationImportSelector.java | ||
+ | 方法 selectImports | ||
+ | |||
+ | -> 方法 getAutoConfigurationEntry | ||
+ | |||
+ | -> 方法 getCandidateConfigurations | ||
+ | |||
+ | -> SpringFactoriesLoader.loadFactoryNames | ||
+ | |||
+ | 加载所有 jar 包下 META-INF/spring.factories | ||
+ | |||
+ | 关键位置: | ||
+ | |||
+ | spring-boot-2.3.4.RELEASE.jar | ||
+ | |||
+ | spring-boot-autoconfigure-2.3.4.RELEASE.jar | ||
+ | |||
+ | 尤其是 | ||
+ | |||
+ | spring-boot-autoconfigure-2.3.4.RELEASE.jar | ||
+ | |||
+ | 的 /META-INF/spring.factories | ||
+ | |||
+ | 里面有大量自动配置类 | ||
+ | |||
+ | 最后再进行条件装配 | ||
| | | | ||
|- | |- | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |AutoConfigurationPackages.java | ||
+ | static class Registrar | ||
+ | |||
+ | 导入 @SpringBootApplication 注解标注类的包下的所有组件 | ||
+ | | | ||
| | | | ||
|} | |} |
2023年3月1日 (三) 10:48的最新版本
@SpringBootApplication | ||||||
---|---|---|---|---|---|---|
@SpringBootConfiguration | @EnableAutoConfiguration | @ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) }) | ||||
@Configuration | @AutoConfigurationPackage | @Import(AutoConfigurationImportSelector.class) | ||||
@Retention(RetentionPolicy.RUNTIME) | @Documented | @Inherited | //给容器中导入一个组件
@Import(AutoConfigurationPackages.Registrar.class) |
AutoConfigurationImportSelector.java
方法 selectImports -> 方法 getAutoConfigurationEntry -> 方法 getCandidateConfigurations -> SpringFactoriesLoader.loadFactoryNames 加载所有 jar 包下 META-INF/spring.factories 关键位置: spring-boot-2.3.4.RELEASE.jar spring-boot-autoconfigure-2.3.4.RELEASE.jar 尤其是 spring-boot-autoconfigure-2.3.4.RELEASE.jar 的 /META-INF/spring.factories 里面有大量自动配置类 最后再进行条件装配 |
||
AutoConfigurationPackages.java
static class Registrar 导入 @SpringBootApplication 注解标注类的包下的所有组件 |