解决SpringBoot循环依赖

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

casClientController (field private org.jeecg.modules.system.service.ISysUserService org.jeecg.modules.cas.controller.CasClientController.sysUserService)

sysUserServiceImpl (field private org.jeecg.common.system.api.ISysBaseAPI org.jeecg.modules.system.service.impl.SysUserServiceImpl.sysBaseAPI)

sysBaseApiImpl (field private org.jeecg.modules.message.websocket.WebSocket org.jeecg.modules.system.service.impl.SysBaseApiImpl.webSocket)
┌─────┐
| webSocket defined in file [E:\MyProjects\jeecg-boot\jeecg-boot\jeecg-boot-module-system\target\classes\org\jeecg\modules\message\websocket\WebSocket.class]
↑ ↓
| valveServiceImpl (field private org.jeecg.modules.message.websocket.WebSocket org.jeecg.modules.valve.service.impl.ValveServiceImpl.webSocket)
└─────┘

可见在WebSocket.class中引用了valveServiceImpl ,然后在ValveServiceImpl中又引用了webSocket,造成循环引用。
解决办法:
@Autowired
@Lazy
private WebSocket webSocket;

在两者其中的一个引用上加 @Lazy注解,解决

你可能感兴趣的:(SpringBoot)