Skip to content

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

@Leon116

Description

@Leon116

Hey,

seems like you can create Spring Beans from Flyway Java-based migrations so that they're injected into the Flyway instance by Spring's DI mechanism, even though the migrations are located outside the configured Flyway locations. Since the migrations are Spring Beans themselves you can also inject other beans into them.

When doing so, an exception arises on startup because a circular bean dependency is detected. This issue has also been discussed in flyway/flyway#1062.
I created a minimal example that shows that issue. I also found out that injecting Spring Beans into Java-based Flyway migrations is only a problem if these beans are somehow associated with JPA. In other cases the migrations work just fine.

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