Skip to content

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

@denis111

Description

@denis111

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.

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions