Constructor Injection - raisercostin/software-wiki GitHub Wiki

  • springboot-2.6.6 checks circular dependencies for setter injection as well (@Autowired fields). If we use Constructor Injection with final not null fields it will be almost impossible to compile.
2022-04-02 18:04:36.375+0300 73011 #ERROR [main           ] 

***************************
APPLICATION FAILED TO START
***************************

Description:

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

   main defined in file [Main.class]
┌─────┐
|  field1 (field private ClassB ClassA.field2)
↑     ↓
|  field2 (field ClassA ClassB.field1)
└─────┘



Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application 
to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle 
automatically by setting spring.main.allow-circular-references to true.