-
Notifications
You must be signed in to change notification settings - Fork 40.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Circular Dependency Issue - V2.6 to Latest #36286
Comments
Please see this section of the 2.6 release notes. |
@philwebb Reviewed the Circular Dependencies section and am aware of the applications.properties file workaround (not recommended). There should not be a cyclic dependency after using one of the resolution methods. In this example, setter injection is used. See code above. |
What resolution method are you talking about? A depends on B and B depends on A so, conceptually, there is clearly a cycle. It looks like you believe that setter injection should fix the cycle. Can you expand on that? |
@snicoll Setter injection using "@Autowired" annotation. See https://www.baeldung.com/circular-dependencies-in-spring#3-use-setterfield-injection for more information. |
This article lists workarounds to make things work despite the circular dependency, but it doesn't fix the circular dependency itself. @snicoll 's comment still stands and so does the release notes. If you believe this article is misleading, please reach out to the authors. |
@bclozel This is one of the common methods to resolve the circular dependency issue. Also mentioned in the Spring documentation (https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html#beans-dependency-resolution). This method should prevent Spring from injecting the dependencies while the objects are created during context loading. Any suggestions? |
It doesn't resolve a circular dependency issue. It's still very much there, just slightly hidden. You should either refactor your code (recommended) or set |
@wilkinsona Code provided is a simple example - refactoring is not necessary. Setting Using setter injection as one of the resolution methods specified in the Spring documentation should not throw an exception. See exception details below:
|
It isn't recommended as we believe that refactoring your code to remove circular dependencies of any form is a better approach.
Then please set the property. That's what it's there for. |
Having an issue resolving circular dependency in a Spring Boot Starter project (version 3.1) with Gradle.
Using setter injection with
@Autowired
annotation.After building the project, the following output displayed:
*Note: Project ran successfully with an older Spring Boot version (2.5.15).
Also tested it using 2.6.0 - same issue occurred.
Appears to be an issue with versions 2.6 and above.
Application code below:
MainApp.java
ClassA.java
ClassB.java
The text was updated successfully, but these errors were encountered: