spring boot
2021-02-28 23:37:46 11 举报
自动装配原理
作者其他创作
大纲/内容
applicationContext.addBeanFactoryPostProcessor
AbstractApplicationContextrefresh()
SpringApplicationRunListeners = this.getRunListeners(args)获取所有的SpringApplicationRunListenerlisteners.starting();
初始话所有的ApplicationListener
将applicationArguments注入到ioc容器中
ConfigurationClass
AnnotationConfigServletWebServerApplicationContext
BeanDefinitionHolder
遍历ApplicationListener的onApplicationEvent
new SpringApplication(primarySources)
listeners.contextPrepared(context)
遍历调用所有的applicationListener start方法
processedBeans
configureProfiles
StandardServletEnvironment
regularPostProcessors
初始化PropertySourcesPropertyResolver
处理PropertySource注解
处理ComponentScan注解
ConfigurationClassPostProcessor
获取启动时参数
reactive
初始化
processPropertySource(propertySource)
demoApplication
封装成
都依赖BeanDefinitionRegistry
处理Import注解
配置资源
=发布启动容器完成事件
遍历执行ApplicationContextInitializerinitialize()
模版方法,用于用户自定义扩展
激活profile文件
SimpleApplicationEventMulticastermulticastEvent()
读取的所有的配置都是从所有jar包的META-INF/spring.fattories文件中读取
推断出主进程类
添加customizePropertySources
ServletWebServerApplicationContextrefresh()
EventPublishingRunListener
获取在初始化的时候拿到的所有ApplicationContextInitializer
new XmlBeanDefinitionReader
处理包装类
判断是否有spring.beaninfo.ignore配置加入到Environment中this.configureIgnoreBeanInfo(environment);
servlet
this.applyInitializers(context);应用所有的ApplicationContextInitializer
广播Environment加载完毕listeners.environmentPrepared()
创建ApplicationConversionService赋值给context里
this.webApplicationType
配置多环境
this.refreshContext(context);刷新容器
处理compnent注解
processImports()
遍历registry.getBeanDefinitionNames() 寻找被Configuration注解的类
new AnnotatedBeanDefinitionReader
遍历所有实现PriorityOrdered的BeanDefinitionRegistryPostProcessors
ApplicationContext
转换服务
new ClassPathBeanDefinitionScanner
registryProcessors
listeners.started(context);
configurePropertySources
DefaultApplicationArguments
AnnotationConfigReactiveWebServerApplicationContext
createBeanDefinitionLoader
run(String... args)
ComponentScanAnnotationParserparser()
将上面设置好的Env设置到context里
default
configClass.addImportedResource
invokeBeanFactoryPostProcessors
获取主启动类的包路径
new GroovyBeanDefinitionReader
Spring boot 启动流程
SharedMetadataReaderFactoryContextInitializer
ConfigurationClassParser.parser
this.componentScanParser.parse
SharedMetadataReaderFactoryContextInitializer.CachingMetadataReaderFactoryPostProcessor()
初始化所有的ApplicationContextInitializer
currentRegistryProcessors
ClassPathBeanDefinitionScanner
postProcessBeanDefinitionRegistry
创建 ConfigurableApplicationContextcontext = this.createApplicationContext();
doProcessConfigurationClass
AbstractEnvironment
initialize()
processConfigurationClass
AnnotationConfigApplicationContext
将主程序DemoApplication通过AnnotatedBeanDefinitionReader注册到ioc容器中
通知所有SpringApplicationRunListener执行environmentPrepared
this.configureEnvironment
listeners.contextLoaded(context)
处理ImportResource注解
继承初始化
收藏
0 条评论
回复 删除
下一页