Skip to content

Startup failure due to non-empty schema when using Flyway and Spring Integration's DataSource initialization #28079

Closed
@agebhar1

Description

@agebhar1

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.

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