提前说明
DService实例属性注入D1Service实例,D1Service实例属性注入DService实例,通过调试看spring是如何解决DService实例与D1Service实例的相互依赖的情况的。
在bean实例化时,先实例化D1Service。
D1Service对象实例化
org.springframework.beans.BeanUtils
D1Service 对象被添加到三级缓存singletonFactories中
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
D1Service 在属性注入时,获取DService的属性值
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
获取DService的bean实例
org.springframework.beans.factory.support.AbstractBeanFactory
DService 对象的实例化
org.springframework.beans.BeanUtils
DService 对象被添加到一级缓存singletonFactories中
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
DService 在属性注入时,获取D1Service的属性值
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
org.springframework.beans.factory.support.DefaultListableBeanFactory
获取D1Service的bean实例
org.springframework.beans.factory.support.DefaultListableBeanFactory
org.springframework.beans.factory.support.AbstractBeanFactory
尝试从一、二、三级缓存中获取D1Service
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
执行getEarlyBeanReference方法获取D1Service对象
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
将D1Service的对象从三级缓存中取出,放到二级缓存中
返回d1Service未初始化的对象
Dservice完成d1Service属性的注入
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
DService进行实例化
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
DService放入一级缓存,并从一二级缓存删除
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry