Skip to content

Circular dependency issue when injecting Spring Beans into Flyway Java-based migrations #46677

@Leon116

Description

@Leon116

Hey Spring Boot Team,

I already reported this in the spring-data-jpa repository (see spring-projects/spring-data-jpa#3959), but was sent here. I'm facing a circular dependency problem using Flyway Java-based migrations. This issue has also been discussed in flyway/flyway#1062 (comment).

If you're initializing Flyway Java-based migrations as Spring Beans, they're injected into the Flyway instance using Spring's DI mechanism. This can be found in FlywayAutoConfiguration.
Since the Java-based migrations are Spring Beans themselves, you can inject other beans. If those beans are somehow associated with JPA, the application fails on startup because a circular dependency between the EntityManagerFactory and Flyway is detected. This dependency between database initializing beans and dependent beans is documented here.

I've created a minimal example that shows this issue. Is this the desired behavior? In flyway/flyway#1062 there is a suggested workaround, but it feels like missing the point having Java-based migrations as Spring beans and not being able to use the JPA layer out of the box.

Best Regards Leon

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions