1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| - refresh() -> invokeBeanFactoryPostProcessors() - ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry() - ConfigurationClassPostProcessor.processConfigBeanDefinitions() - 1.parser.parse(candidates)比如此时candidates是SpringApplication启动类 - ConfigurationClassParser.parse() - 1.不同类型的 beanDefinition,调用不同的 parse(),parse()方法 -> processConfigurationClass() - 2.this.deferredImportSelectorHandler.process() 处理入口 - ConfigurationClassParser.DeferredImportSelectorHandler.process() - 1.创建 DeferredImportSelectorGroupingHandler - 2.deferredImports排序 - 3.deferredImports注册 - 4.handler.processGroupImports(); // 处理 - ConfigurationClassParser.DeferredImportSelectorGroupingHandler#processGroupImports() - 1.遍历groupings.values(),调用grouping.getImports() - ConfigurationClassParser.DeferredImportSelectorGrouping#getImports() - 1.this.group.process() - AutoConfigurationImportSelector.AutoConfigurationGroup#process() - 1.getAutoConfigurationEntry(getAutoConfigurationMetadata(),annotationMetadata) - AutoConfigurationImportSelector#getAutoConfigurationEntry() - 1.isEnabled(annotationMetadata)判断ENABLED_OVERRIDE_PROPERTY属性,是否启用自动配置 - 2.getCandidateConfigurations(): 通过 spi 加载 spring.factories 里所有的 AutoConfiguration 配置类 - 3.removeDuplicates() 移除重复配置 - 4.getExclusions(): exclusions处理 - 5.filter(): 遍历AutoConfigurationImportFilter类,做filter处理 - 6.fireAutoConfigurationImportEvents(): 发布AutoConfigurationImportEvent事件 - 2.this.group.selectImports() - AutoConfigurationImportSelector.AutoConfigurationGroup#selectImports() 做排序并返回 - 2.processImports() - ConfigurationClassParser#processImports():就是ConfigurationClassParser里类对@Import注解的处理逻辑
|