SpringBoot自动配置
@SpringBootApplication包含@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan、@ConfigurationPropertiesScan
SpringApplication.run启动流程中与自动配置相关流程:
-
SpringApplication启动
org.springframework.boot.SpringApplication#run(java.lang.Class<?>, java.lang.String…)
-
创建ApplicationContext
org.springframework.boot.SpringApplication#createApplicationContext
-
注册ConfigurationClassPostProcessor
org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)
-
refresh invoke BeanFactoryPostProcessor
org.springframework.context.support.AbstractApplicationContext#invokeBeanFactoryPostProcessors
-
postProcess @Configuration
org.springframework.context.annotation.ConfigurationClassPostProcessor#postProcessBeanDefinitionRegistry
-
process启动类SpringApplication配置类
org.springframework.context.annotation.ConfigurationClassParser#doProcessConfigurationClass
-
ComponentSacn,默认扫描启动类包路径
org.springframework.context.annotation.ComponentScanAnnotationParser#parse
-
process imports
org.springframework.context.annotation.ConfigurationClassParser#processImports
-
解析@SpringBootApplication注解的Imports,包括AutoConfigurationImportSelector
-org.springframework.context.annotation.ConfigurationClassParser#processImports- org.springframework.boot.autoconfigure.AutoConfigurationPackages$Registrar
- org.springframework.boot.autoconfigure.AutoConfigurationImportSelector
- org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar
- org.springframework.boot.context.properties.ConfigurationPropertiesScanRegistrar
-
处理ImportSelector
org.springframework.context.annotation.ConfigurationClassParser.DeferredImportSelectorHandler#process -
加载EnableAutoConfiguration扩展点
org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.AutoConfigurationGroup#process