I have question about spring framework. So assume there is following code:
@Service
@Scope("prototype")
public class A
{
@Autowired
private B b;
public void foo()
{
System.out.println("A foo");
}
}
@Service
@Scope("prototype")
public class B
{
@Autowired
private A a;
public void foo()
{
System.out.println("B foo");
}
}
and there is following code which starts application context:
@SpringBootApplication
public class DemoApplication
{
@Autowired
private A a;
public static void main(String[] args)
{
SpringApplication.run(DemoApplication.class, args);
}
}
if I start spring context then it will throw circular reference exception(which is expected). My question is why if I change the scope of bean A to singleton then everything will work fine?