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.

Comment From: mbhave

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

Comment From: denis111

@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.

Comment From: mbhave

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.

Comment From: codergmc

@denis111 Can you explain why are you use one SpringLiquibase depends on the other SpringLiquibase? The problem happened on https://github.com/spring-projects/spring-boot/blob/ce1dff86dfaea26a03ef0fc0918858bb14397727/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurer.java#L110 @philwebb

Comment From: denis111

@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.