循环依赖

1 、默认情况,用无参构造方法,或者只有一个构造方法就用那一个 
2 、程序员用指定的构造方法入参值,通过 getbean ( )或者beanoefinition.getconstructorArgumentvaiues()指定,那就用所匹配的构造方法
3 、程序员想让 spring 自动选择构造方法以及构造方法的入参值, autwire="constructor"
4 、程序员通过,@Autowired 注解指定了某个构造方法,但是希望Spring自动找该构方法的入参值


先创建Aservice,执行Aservice的生命周期
1、creatingSet<Aservice>
2、实例化Aservice-->得到一个对象-->singletonFactories<AService:lambda<Aservice原始对象>
3、填充Bservice属性-->去单例池中找BService-->zhouyuMap-->没有则创建BService
4、填充Cservice属性
5、初始化前、初始化
6、初始化后-->Aservice代理对象
7、放入单例池


创建Bservice,执行Bservice的生命周期
2.1、实例化Bservice-->得到一个对象-->zhouyuMap<Bservice:Bservice原始对象>
2.2、填充Aservice属性-->去单例池中找Aservice-->creatingSet-->出现了循环依赖-->earlySingletonObjects-->singletonFactories-->lambda-->执行-->earlysingletonObjects
2.3、填充其他属性
2.4、初始化前、初始化
2.5、初始化后
2.6、放入单例池
org.springframework.context.annotation.ClassPathBeanDefinitionScanner#scan

org.springframework.beans.factory.config.ConfigurableListableBeanFactory#preInstantiateSingletons

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#findAutowiringMetadata

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#postProcessProperties

org.springframework.context.annotation.CommonAnnotationBeanPostProcessor#findResourceMetadata

org.springframework.context.annotation.CommonAnnotationBeanPostProcessor#postProcessProperties

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#getSingleton(java.lang.String, boolean)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance

org.springframework.context.annotation.ConfigurationClassPostProcessor#processConfigBeanDefinitions

认证源码

 

posted @ 2022-08-31 23:31  VNone  阅读(32)  评论(0)    收藏  举报