介绍
在写业务时,调试出现Spring循环依赖报错,运行不了。
bash
The dependencies of some of the beans in the application context form a cycle:
authUserController
┌─────┐
| authUserService
↑ ↓
| loginTypeHandlerFactory
↑ ↓
| loginByEmail
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.解决
在循环其中一方加上@Lazy,推迟 Bean 实例化就好了
