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

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

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

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

問題:

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

以上的實例中IndexService依賴IndexDao,IndexDao中依賴IndexService。

spring在bean的實例化過程:

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

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

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

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

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

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

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

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

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

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

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

相關(guān)文章

最新評論