記一次Spring 循環依賴的踩坑過程

問題

今日Springboot項目在啓動的時候報錯了,錯誤如下

ERROR SpringApplication - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxxxxxx': Unsatisfied dependency expressed through field 'xxxxxxxxxxxx'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'xxxxxxxxxxxxxx': Bean with name 'xxxxxxxxxxxx' has been injected into other beans [xxxxxxxxxxxxxx] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'xxxxxxxxxxxxxx' with the 'xxxxxxxxxxxxxx' flag turned off, for example.

 排查過程

通過網上查閱資料得知可能是Spring循環的問題,但是Spring官方其實已經通過三級緩存解決了這個問題,但是現在報錯只能先使用 @Lazy註解看一看,但是運行之後還是不行,這下可就麻煩了,但是考慮之前是沒有問題的,但是這次突然問題,一定最近幾天提交的代碼有問題,於是查閱代碼提交記錄,只有在循環依賴的一個類中加了一個異步的方法,難道是這個異步方法導致了循環依賴的問題???帶着這樣的疑問開始查閱相關資料,果然有這樣的問題存在,大概就是因爲異步方法會改變三級緩存的原始對象,導致在最終實例化依賴對象的時候出現異常,具體的細節可以看下這篇博文分析https://segmentfault.com/a/1190000018835760

推薦閱讀:https://segmentfault.com/a/1190000018835760

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章