Skip to content
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

Since 2.5.1, a circular reference is created when one SpringLiquibase bean is configured to depend on another #27131

Closed
denis111 opened this issue Jun 30, 2021 · 5 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@denis111
Copy link

denis111 commented Jun 30, 2021

Hello,
I have two SpringLiquibase beans defined in different classes and modules in multi-module Gradle project, one of them depends on main liquibase bean. This code works perfect with v2.5.0 and below:

public class MainLiquibaseConfig implements InitializingBean {
...

  @Bean
  @Lazy(false)
  public SpringLiquibase liquibase() {
    ...
  }
}

public class Oauth2DatabaseConfig {
...

  @Bean
  @Lazy(false)
  @DependsOn("liquibase")
  public SpringLiquibase oauth2SpringLiquibase() {
    ...
  }
}

But starting with Spring Boot 2.5.1 I've got an exception on start-up:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [com/tranxfer/database/MainLiquibaseConfig.class]: Circular depends-on relationship between 'liquibase' and 'oauth2SpringLiquibase'
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)

I can't see how 'liquibase' bean can depend on 'oauth2SpringLiquibase', besides as I said before it works with Spring Boot 2.5.0 and below. Also I'm not sure if this applies to only SpringLiquibase beans or any other bean types.

I tried some workarounds without luck: If i remove DependsOn annotation then oauth2SpringLiquibase gets executed first, if I replace DependsOn by ConditionalOnBean oauth2SpringLiquibase gets never executed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 30, 2021
@snicoll snicoll changed the title [bug] False positive circular reference detection on SpringLiquibase beans since v2.5.1 False positive circular reference detection on SpringLiquibase beans since v2.5.1 Jun 30, 2021
@mbhave
Copy link
Contributor

mbhave commented Jul 1, 2021

@denis111 Can you provide a minimal sample that we can run to reproduce the issue?

@mbhave mbhave added the status: waiting-for-feedback We need additional information before we can continue label Jul 1, 2021
@denis111
Copy link
Author

denis111 commented Jul 2, 2021

@mbhave sure, here's the sample project https://github.com/denis111/spring-boot-issue-27131 . It does nothing, it's very dumb but you can see that it executes fine with 2.5.0 and fails with 2.5.2.

@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 Jul 2, 2021
@mbhave
Copy link
Contributor

mbhave commented Jul 2, 2021

Thanks for the sample. I think it's the fix for #26692 that's causing this. We probably didn't consider the case where beans detected by the the DatabaseInitializerDetectors might have already have a depends-on relationship. Flagging for team-attention to get the rest of the team's thoughts on this.

@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Jul 2, 2021
@codergmc
Copy link

codergmc commented Jul 5, 2021

@denis111 Can you explain why are you use one SpringLiquibase depends on the other SpringLiquibase?
The problem happened on

beanDefinition.setDependsOn(merge(beanDefinition.getDependsOn(), previousInitializerBeanName));

@philwebb

@denis111
Copy link
Author

denis111 commented Jul 5, 2021

@codergmc Because the second liqiubase needs tables created by first liquibase. The first one is like main application database tables that always needed and the second one is like optional module/plugin that can be on classpath or not.
Anyway that worked fine until v2.5.1.

@philwebb philwebb added type: regression A regression from a previous release and removed for: team-attention An issue we'd like other members of the team to review status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jul 7, 2021
@philwebb philwebb added this to the 2.5.x milestone Jul 7, 2021
@wilkinsona wilkinsona self-assigned this Jul 8, 2021
@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.3 Jul 19, 2021
@wilkinsona wilkinsona changed the title False positive circular reference detection on SpringLiquibase beans since v2.5.1 False positive circular reference detection on SpringLiquibase beans since 2.5.1 Jul 19, 2021
@wilkinsona wilkinsona changed the title False positive circular reference detection on SpringLiquibase beans since 2.5.1 Since 2.5.1, a circular reference is created when one SpringLiquibase bean is configured to depend on another Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

6 participants