Skip to content

Error dependency cycle between beans when upgrade spring boot version from 3.4.3 to 3.4.4 #44988

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

Closed
kridtakom opened this issue Apr 3, 2025 · 6 comments
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue

Comments

@kridtakom
Copy link

I am currently upgrading the Spring Boot and Spring Cloud versions for my project as follows:

build.gradle file

plugins {
    id 'org.springframework.boot' version '3.4.4'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2024.0.1"
    }
}

error log

***************************

APPLICATION FAILED TO START

***************************

� Description:

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

   citizenController defined in URL [jar:nested:/app/app.jar/!BOOT-INF/classes/!/com/company/project/abc/controller/CitizenController.class]

�

      ↓

   citizenServiceImpl defined in URL [jar:nested:/app/app.jar/!BOOT-INF/classes/!/com/company/project/abc/service/CitizenServiceImpl.class]

�

      ↓

   digitallendingDataSourceImpl defined in URL [jar:nested:/app/app.jar/!BOOT-INF/classes/!/com/company/project/abc/datasource/DigitallendingDataSourceImpl.class]

�

      ↓

   com.company.project.digitallendingclient.DigitallendingClient

┌─────┐

|  consulAutoServiceRegistrationListener defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class]

↑     ↓

|  consulAutoServiceRegistration defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class]

↑     ↓

|  consulServiceRegistry defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistryAutoConfiguration.class]

↑     ↓

|  ttlScheduler defined in class path resource [org/springframework/cloud/consul/support/ConsulHeartbeatAutoConfiguration.class]

↑     ↓

|  actuatorHealthStatusProvider defined in class path resource [org/springframework/cloud/consul/support/ConsulHeartbeatAutoConfiguration$ActuatorBasedApplicationStatusProviderConfig.class]

↑     ↓

|  healthEndpoint defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]

↑     ↓

|  healthContributorRegistry defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]

↑     ↓

|  dbHealthContributor defined in class path resource [org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.class]

↑     ↓

|  documentDetailRepository defined in com.company.project.abc.repository.document.DocumentDetailRepository defined in @EnableRedisRepositories declared on RedisRepositoriesRegistrar.EnableRedisRepositoriesConfiguration

└─────┘

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.

I downgraded Spring Boot to version 3.4.3 and Spring Cloud to version 2024.0.0, and everything is functioning well.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 3, 2025
@wilkinsona
Copy link
Member

Thanks for the report, unfortunately it doesn't contain enough information to diagnose the problem. I suspect it may be related to #44706 but that's only a slightly educated guess based on the presence of DataSourceHealthContributorAutoConfiguration in the cycle.

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Apr 3, 2025
@kridtakom
Copy link
Author

I am using Spring Boot version 3.4.4 and have set management.health.db.enabled=false. Everything is functioning well.

management:
  health:
    db:
      enabled: false

Can you identify the root cause of the dependency cycle error?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 3, 2025
@wilkinsona
Copy link
Member

Thanks. That's another indicator that the changes made for #44706 are involved here, but I don't yet fully understand why that's the case for a couple of reasons:

  • Both 3.4.3 and 3.4.4 retrieve DataSource beans in a way that permits eager initialization but it would appear that's causing a problem in 3.4.4 while it did not in 3.4.3
  • It would appear that the factory bean for your DocumentDetailRepository does not provide Framework with information about the type that it will produce so it's being created in order to answer that question. My understanding is that Spring Data does provide this information using an attribute on the bean definition and it's not clear why it is apparently ineffective

A sample that reproduces the problem would be very helpful in getting to the bottom of the current behavior and figuring out the best way to fix it.

@wilkinsona
Copy link
Member

After some discussion with @jhoeller I now understand why Boot 3.4.3 and 3.4.4 are behaving differently. It's due to 3.4.4 filtering out non-singletons which triggered some unwanted early initialization of factory beans. This has been addressed in Spring Framework 6.2.6-SNAPSHOT through spring-projects/spring-framework#34710.

@kridtakom, the Framework change should hopefully fix your problem. In the absence of an example that we can try ourselves, can you please test 6.2.6-SNAPSHOT against your app? It's available from https://repo.spring.io/snapshot.

@kridtakom
Copy link
Author

Thank you for your suggestion. I want to know the plan for releasing Spring 6.2.6 and Spring Boot 3.4.5 ?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 6, 2025
@bclozel
Copy link
Member

bclozel commented Apr 6, 2025

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 6, 2025
@bclozel bclozel closed this as completed Apr 9, 2025
@bclozel bclozel added status: duplicate A duplicate of another issue for: external-project For an external project and not something we can fix and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants