错误代码:
@Service
public class A {
@Autowired
private B b;
}
@Service
public class B {
@Autowired
private A a;
}
报错提示:
he dependencies of some of the beans in the application context form a cycle:
┌─────┐
| a (field private com.hwzt.circle.service.B com.hwzt.circle.service.A.b)
↑ ↓
| b (field private com.hwzt.circle.service.A com.hwzt.circle.service.B.a)
└─────┘
错误原因:
循环依赖
解决方法:
添加@Lazy注解
@Service
public class A {
@Autowired
@Lazy
private B b;
}
@Service
public class B {
@Autowired
private A a;
}
应用启动成功