A maven project has spring-boot-starter-parent as its parent. I just switched the version from 2.3.1.RELEASE to 2.6.7.
Suddenly, the springboot application that uses this project has cyclic dependencies with this error:
The dependencies of some of the beans in the application context form a cycle: org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration ┌─────┐ | com.mycompany.spring.logging.configuration.InterceptorConfiguration (field com.mycompany.spring.logging.RequestInterceptor com.mycompany.spring.logging.configuration.InterceptorConfiguration.interceptor) └─────┘ 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.
No Java source has changed, no other dependencies have changed. The classes in the error (InterceptorConfiguration and RequestInterceptor) are in another internal library and they have not changed.
I’m a bit confused about what’s causing the circular reference, and I’m not sure how to resolve it. Setting spring.main.allow-circular-references=true
seems like a less-than-ideal solution.
Advertisement
Answer
As per documentation,
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6.0-M2-Release-Notes#circular-references-prohibited-by-default, Circular references are not prohibited by default. Circular references can be allowed again by setting spring.main.allow-circular-references
to true
So, there are chances that your application had circular dependency earlier as well but was working as Spring allowed it by default. Best solution is to identify and remove the circular references.