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

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

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

看過一次spring公開課,記錄一下bean的循環(huán)引用問題。

問題:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

相關(guān)文章

最新評(píng)論