当前位置:网站首页>详解三级缓存解决循环依赖
详解三级缓存解决循环依赖
2022-06-10 19:29:00 【-隐函数-】
循环依赖
所谓的循环依赖就是
A对象创建的时候需要通过@Autowired依赖注入B对象才能创建成功,B对象创建的时候需要@Autowired依赖注入A对象才可以创建成功,这种情况之下,我们称之为循环依赖,循环依赖主要发生在Bean的set赋值这个过程
其实@Autowired就已经解决了循环依赖的问题
缓存

三级缓存解决循环依赖

我们以A对象为例,A对象通过BeanFunctionRead读取配置文件,利用反射机制进行实例化创建之后,因为此时没有赋值初始化等,还不是一个完整的bean所以无法放进一级缓存,先放入三级缓存之中,
然后调用Autowired注解进行属性的赋值,发现B对象还没有创建出来,先暂停,准备创建B对象
B对象利用反射机制实例化之后也放进三级缓存当中,然后进行Autowired注解进行属性赋值,
发现需要A注解,那么从一、二、三 级缓存当中依次去寻找,发现三级缓存当中存在A注解,那么就调用ObjectFactory中的getObject方法进行调用,然后B把A放进二级缓存中,B进行赋值
然后执行其他阶段,直至把B创建出来放进一级缓存当中,之后清空二三缓存
B创建成功之后,A可以获取B就可以继续进行创建,然后A开始进行Autowired注解进行赋值,然后继续执行其他阶段,然后A对象创建成功,放进一级缓存当中,同时清空二三缓存
边栏推荐
- [enter textbook latex record]
- 手写代码 bind
- 传音 Infinix 新机现身谷歌产品库,TECNO CAMON 19 预装 Android 13
- Routine solution - the problem of horse walking on the chessboard
- C语言 浮点数 储存形式
- 利用阿里云国际购买的服务器搭建个人网站步骤
- Zabbix_监控ssh/crond服务-微信告警
- The old programmer said: stop translating the world, developers should return to programming
- 江波龙 FORESEE XP2000 PCIe 4.0 SSD 多重加密功能,锁定数据安全
- HM3416H降压IC芯片PWM/PFM 控制 DC-DC 降压转换器
猜你喜欢

Key points of lldp protocol preparation

Recommend a crud tool that may become the best crud tool in 2019 during the National Day

Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data

SBC芯片35584数据手册预调节器翻译

玩艺术也得学数学?

首批!青藤通过信通院CWPP能力评估检验

一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息

CVPR 2022 Tsinghua University proposed unsupervised domain generalization (UDG)

Rotated sorted array

Solution to the problem that JLINK CDC UART driver cannot be installed normally under win7 system
随机推荐
Zabbix_ Principle Architecture - installation and deployment - Custom monitoring
软件定义边界(SDP)
Tutoriel Microsoft Word "5", comment changer les marges de page et créer une barre de nouvelles en word?
KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器
Key points of lldp protocol preparation
The new audio infinix machine appears in the Google product library, and Tecno CaMon 19 is pre installed with Android 13
Enhance the target method with surround notifications - extract notes
Solving Bob's survival problem by trilogy routine
首批!青藤通过信通院CWPP能力评估检验
[enter textbook latex record]
Handwritten code bind
Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation
Esp8266 system environment setup
Tidb - quick start, cluster setup
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE tha
How to realize face verification quickly and accurately?
Which school do you choose after the college entrance examination? VR panoramic campus all-round display
FPGA状态机
利用阿里云国际购买的服务器搭建个人网站步骤
localhost和127.0.0.1的区别?