Suppose I have two classes
Class A
Class B
Now, Class A has dependency on Class B and Class B has dependency on class B.
Looks like
class A {
private B b;
public A(B b) {
this.b = b;
}
}
class B {
private A a;
public B(A a) {
this.a = a;
}
}
The bean configuration for the same will be
@Bean
public A getA() {
return new A(getB());
}
@Bean
public B getB() {
return new B(getA());
}
This code results in a deadlock situation as one depeneds on the other. How to instantiate Beans in such case?