包啓動報BeanCurrentlyInCreationException解決方案

今天項目出現了一個問題,maven打包的時候沒有問題,啓動的時候就報了

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entPayTask': Bean with name 'entPayTask' has been injected into other beans [zhituiIncomeServiceImpl] 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.

這是Spring容器創建bean的時候,出現循環引用的時候報的異常。

什麼是循環引用

循環引用,簡單的說就是,A依賴B,B依賴C,C又依賴A,這樣形成了一個閉環。

解決辦法

按照報錯提示在引用的bean上加一個@Lazy屬性。Spring的懶加載是在需要用到bean的時候,就是getBean的時候才創建,這樣就不會報BeanCurrentlyInCreationException。

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