1. 程式人生 > >Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] in its raw version as part of a circular reference, b

Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] in its raw version as part of a circular reference, b

 

啟動專案,通過@Autowired注入物件,出現迴圈依賴,導致專案啟動失敗,具體報錯資訊如下: 

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxtController': 
Unsatisfied dependency expressed through field 'xxxService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: 
Error creating bean with name 'xxxService': Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] 
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

  

Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] in its raw version as part of a circular reference, but has eventually been wrapped
翻譯:xxxService 這個bean已經被注入到xxxServiceA、xxxServiceB這兩個bean中了,他們之間存在迴圈引用(依賴),也就是說:xxxServiceA中注入了xxxService,而xxxService中也要注入xxxServiceA,所以就會出現這種情況

 

參考:https://www.cnblogs.com/leng39/p/9530569.html