A simple test

@SpringBootTest
class ApplicationTests {

    @Test
    void contextLoads() {
    }

}

fails if Spring Integration JDBC, Flyway and an embedded database is used since Spring Boot v2.5.3 with:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "PUBLIC" but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.

A minimal failing example can be found here https://github.com/agebhar1/spring-boot-flyway-si-jdbc and the details for running tests here https://github.com/agebhar1/spring-boot-flyway-si-jdbc/actions/runs/1258717007.

The problem is that with embedded database tests IntegrationJdbcConfiguration with IntegrationDataSourceInitializer (from Spring Boot autoconfiguration) runs after Flyway in Spring Boot v2.5.1 and since Spring Boot v2.5.3 before Flyway hence the database is not empty and Flyway fails.

I suggest to add @AutoConfigureAfter(FlywayAutoConfiguration.class) to IntegrationJdbcConfiguration. And check this also for Liquibase.

Comment From: wilkinsona

This is due to the changes made in https://github.com/spring-projects/spring-boot/commit/433f3d6bc465e7552e696007fb7ad5ee1fb15005 for https://github.com/spring-projects/spring-boot/pull/27215. The problem is that the new AbstractDataSourceInitializerDatabaseInitializerDetector is unordered so the initializers that it detects end up running before Flyway (and Liquibase). The problem doesn't occur in 2.6 due to the changes made for https://github.com/spring-projects/spring-boot/issues/27206.

Comment From: agebhar1

Thanks @wilkinsona for the background details.