FlywayMigrationInitializer

FlywayMigrationInitializer

Hibernate生成所有架构表后,我需要执行Flyway迁移。
在迁移到Spring Boot 2.2之前,此代码可以正常工作

@Configuration
public class BaseFlywayConfiguration {

    /**
     * Override default flyway initializer to do nothing
     */
    @Bean
    FlywayMigrationInitializer flywayInitializer(Flyway flyway) {
        return new FlywayMigrationInitializer(flyway, (f) -> {
        });
    }

    /**
     * Create a second flyway initializer to run after jpa has created the schema
     */
    @Bean
    @DependsOn("transactionManager")
    FlywayMigrationInitializer delayedFlywayInitializer(Flyway flyway) {
        return new FlywayMigrationInitializer(flyway, null);
    }

}


不幸的是,在迁移到Spring Boot 2.2.0之后,我收到了与循环依赖相关的异常

这是日志:

应用程序上下文中某些bean的依赖性形成一个循环:

┌─────┐
|在类路径资源中定义的transactionManager [com / myFleetSolutions / myFleet / organization / configuration / jpa / JPAConfigurationDev.class]
└─────┘

我该如何解决?

最佳答案

理想情况下,您将在flyway中创建所有模式(表,序列等),而不使用Hibernate生成该模式。我建议您导出当前的架构,然后创建一个V1__init-schema.sql以便进行初始化。然后将hibernate.hbm2ddl.auto设置为验证或不验证。

10-06 14:38