Spring
2020-06-01 18:03:05 1 举报
springIOC流程图,结合源码绘制
作者其他创作
大纲/内容
@ComponentScan
反射创建bean实例
获取单例工厂
最最最核心的bean工厂
XML bean
spring.xml
earlySingletonObjects
反射
org.springframework.beans.factory.config.BeanDefinition
if(!beanInstance instanceof FactoryBean || BeanFactoryUtils.isFactoryDereference(name)){return beanInstance;}
BeanDefintionRegistry
判断缓存对象池中是否有
ApplicationContext
解析
ObejctFactory<?> singletonFactory = this.singletonFactories.get(beanName);
返回结果
判断scope类型
注册器
没有,去创建bean
singletonObject
beanName
创建单例bean
beanClass=User.class
循环依赖判断
prototype
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#addSingletonFactory
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean
beanDefinitionMap
读取
ResourceLoader
缓存单例工厂
bean
填充属性,注入bean依赖
Object sharedInstance =
DefaultListableBeanFactory
AnstractBeanFactory
判断是否是FactoryBean
将给定的单例对象添加到此工厂的单例缓存
提前暴露对象,作为依赖注入对象
返回bean
autowireMode=0
User.class
@Conditional
初始化,包括设置Aware属性,处理AOP逻辑
去bean工厂中获取
@ImportResource
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#populateBean
BeanDefinitionReader
DefaultSingletonBeanRegistry
......
ConcurrentHashMap
注册
AbstractAutowireCapableBeanFactory
@Component
@Import
添加到singletonFactories SmartInstantiationAwareBeanPostProcessor#getEarlyBeanReference
BeanDefinition
singletonFacory
new
org.springframework.beans.factory.support.BeanDefinitionRegistry#registerBeanDefinitionfont color=\"#00cccc\
加载
singletonFactories
org.springframework.beans.factory.support.BeanDefinitionRegistry
BeanDefinitionRegistryPostProccessor
缓存singleton工厂
lazyInit = false
singletonObject == null && isSingletonCurrentlyCreation(beanName)
拿到bean
getSingletonBean的逻辑
xuchang
装配
BeanFactory
singletonObject =
先去单例对象池中拿
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance
singleton
context.getBean(\"user\")
scope=singleton
BeanDefintion
装配方式
容器启动创建非懒加载单例bean
XML
singletonObjects
BeanFefinition
0 条评论
下一页