欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單了解spring bean的循環(huán)引用

 更新時(shí)間:2019年08月15日 09:10:22   作者:yongan  
這篇文章主要介紹了簡(jiǎn)單了解spring bean的循環(huán)引用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

看過(guò)一次spring公開(kāi)課,記錄一下bean的循環(huán)引用問(wèn)題。

問(wèn)題:

public class IndexService{
  @Autowired
  IndexDao indexDao;
}
public class IndexDao{
  @Autowired
  IndexService indexService;
}

以上的實(shí)例中IndexService依賴(lài)IndexDao,IndexDao中依賴(lài)IndexService。

spring在bean的實(shí)例化過(guò)程:

先去創(chuàng)建IndexDao bean,

1.創(chuàng)建IndexDao實(shí)例,此時(shí)還沒(méi)有IndexDao bean產(chǎn)生。

2.去配置IndexDao對(duì)象的屬性,這個(gè)屬性就是IndexService,在這個(gè)配置的過(guò)程中會(huì)先把自己(IndexDao)對(duì)象放到singleFactory中;

3.然后去查找IndexService bean去填充,發(fā)現(xiàn)單例池(專(zhuān)門(mén)存放bean)中沒(méi)有,然后去singleFactory中去找,還是沒(méi)有。

4.創(chuàng)建IndexService實(shí)例,此時(shí)還沒(méi)有IndexService bean。

5.去配置IndexService對(duì)象的屬性,這個(gè)屬性就是IndexDao,在這個(gè)配置的過(guò)程中會(huì)先把自己(IndexDao)對(duì)象放到singleFactory中;

6.然后去查找IndexDao bean去填充,發(fā)現(xiàn)單例池中沒(méi)有,然后去singleFactory中去找,發(fā)現(xiàn)有了。

7.然后把屬性填充到IndexService中。

8.經(jīng)過(guò)4,5,6,7后已經(jīng)有了IndexService,并且此時(shí)屬性IndexDao有值了,然后通過(guò)步驟3再將這個(gè)IndexService注入到IndexDao

9.然后繼續(xù)完成IndexDao 后續(xù)的bean的初始化。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論