Spring的refresh方法
2021-04-18 14:46:10 7 举报
AI智能生成
Spring相关的拓展点,供给大家学习,如文中有误请留言交流。
作者其他创作
大纲/内容
invokeBeanFactoryPostProcessors
BeanDefinitionRegistry
1. BeanDefinitionRegistryPostProcessor
postProcessBeanDefinitionRegistry
2. ImportBeanDefinitionRegistrar
基于注解注册BeanDifination
BeanDefinitionRegistryPostProcessor(BeanDefinitionRegistry)
触发执行:postProcessBeanDefinitionRegistry方法
执行顺序
1. PriorityOrdered
2. Ordered
BeanFactoryPostProcessor
postProcessBeanFactory
beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)
LoadTimeWeaverAwareProcessor
ContextTypeMatchClassLoader
registerBeanPostProcessors
BeanPostProcessor
框架内部实现类
BeanPostProcessorChecker
ApplicationListenerDetector
注册BeanPostProcessors
触发顺序
PriorityOrdered
Ordered
注册类型
BeanPostProcessor
MergedBeanDefinitionPostProcessor
整体注册流程
BeanPostProcessorChecker
BeanPostProcessor
MergedBeanDefinitionPostProcessor
ApplicationListenerDetector
initMessageSource
initApplicationEventMulticaster
选举一个应用事件回调接口
工厂中是否包含APPLICATION_EVENT_MULTICASTER_BEAN_NAME名称的bean?
是?ApplicationEventMulticaster
否? SimpleApplicationEventMulticaster
注册到单例工厂中
onRefresh
初始化SpringMVC层面的bean
这个方法主要作用是当Spring的上下文初始化完成之后,会回调这个方法,目前是用来初始化Web的容器
registerListeners
ApplicationEventMulticaster
addApplicationListener
ApplicationListener
addApplicationListenerBean
multicastEvent
finishBeanFactoryInitialization
LoadTimeWeaverAware
getBean
createBean
resolveBeforeInstantiation
applyBeanPostProcessorsBeforeInstantiation
postProcessBeforeInstantiation
CommonAnnotationBeanPostProcessor
@PostConstruct
applyBeanPostProcessorsAfterInitialization
postProcessAfterInitialization
doCreateBean
createBeanInstance
determineConstructorsFromBeanPostProcessors
determineCandidateConstructors
getEarlyBeanReference
getEarlyBeanReference
populateBean
postProcessAfterInstantiation
postProcessProperties
AutowiredAnnotationBeanPostProcessor
@Autowried
@Value
postProcessPropertyValues
initializeBean
applyBeanPostProcessorsBeforeInitialization
postProcessBeforeInitialization
applyBeanPostProcessorsAfterInitialization
postProcessAfterInitialization
AbstractAutoProxyCreator
@Transactional
DefaultListableBeanFactory
preInstantiateSingletons
遍历所有IOC中的beanDefinition对象,开始初始化。
根据Bean的名称在单例工厂中获取是否存在。
创建bean
执行New方法
填充Bean
属性赋值
初始化Bean
postProcessBeforeInitialization
执行Init方法
applyBeanPostProcessorsAfterInitialization
0 条评论
下一页