1. 程式人生 > >解決Spring Boot產生環形注入的問題

解決Spring Boot產生環形注入的問題

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

|  MyController (field private com.zhxy.service.AService com.zhxy.controller.MyController.BService)
↑     ↓
|  BService
└─────┘

啟動spring boot報以上錯誤

錯誤產生原因:BService裡面注入AService使用,AService裡面又注入BService使用

解決方法:在BService的實現類對 AService   加上Spirng的註解 @Lazy

@Autowired

@Lazy

private AService aService ;