What is a circular dependency?
For example, you call Xiaoming, and Xiaoming is also calling you. At this time, the phone will say that the other party is on the phone, and the above error report is this "in progress". The meaning of the code is: if b is injected into a, and a is injected into b, the circular dependency problem will be triggered;
Not much to say about the code:
public class A{
@Autowired
private B b;
}
public class B{
@Autowired
private A a;
}
Solution:
Add the @Lazy annotation to a certain class. The function of this annotation is to delay the loading of one of the beans that depend on each other, so as to solve the problem that Spring does not know which one to initialize first when initializing the bean.
public class A{
@Autowired
@Lazy
private B b;
}
Solve the circular dependency by modifying the yml configuration file
Spring:
main:
allow-circular-references:true
Summarize:
Circular dependent references are discouraged and disabled by default. Don’t use it if you can~~~