【異常】org.springframework.beans.factory.BeanCreationException:...part of a circular reference....

前言 

今天再寫完一個業務,部署服務器項目時報錯:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deviceShelfProductController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'deviceShelfProductServiceImpl': Bean with name 'deviceShelfProductServiceImpl' has been injected into other beans [tradeServiceImpl] 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 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

其中,紅色標註英文的意思爲循環引用,也就是說我在deviceShelfProductServiceImpl中引用注入了tradeServiceImpl,而在tradeServiceImpl中又引用注入了deviceShelfProductServiceImpl,這種情況叫做循環依賴。

解決辦法的話:

1.可以將業務代碼轉移至其中一個業務類中,不要兩個類互相引用

2.業務代碼可能過於繁瑣,不好轉移,那麼可以使用註解@Lazy進行延遲加載,即可避免循環依賴

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