Spring Boot 延迟 Flyway 初始化循环依赖 [英] Spring Boot deferred Flyway inizialization circular dependency

查看:33
本文介绍了Spring Boot 延迟 Flyway 初始化循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Hibernate 生成所有模式表后执行 Flyway 迁移.在迁移到 Spring Boot 2.2 之前,这段代码运行良好

I need to execute Flyway migration after Hibernate generates all the schema table. Before migrating to Spring Boot 2.2 this code worked fine

@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 后,我收到了一个与循环依赖相关的异常

Unfortunately after migrating to Spring Boot 2.2.0 I receive an Exception related to a circular dependency

这是日志:

应用上下文中部分bean的依赖形成一个循环:

The dependencies of some of the beans in the application context form a cycle:

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

┌─────┐ | transactionManager defined in class path resource [com/myFleetSolutions/myFleet/organization/configuration/jpa/JPAConfigurationDev.class] └─────┘

我该如何解决?

推荐答案

我只是在 @SpringBootApplication 类中注入了 Flyway bean,并在 CommandLineRunner init 方法中执行了 flyway.migrate().它在系统启动结束时执行并且工作正常

I've simply Injected Flyway bean in the @SpringBootApplication class, and executed flyway.migrate() in the CommandLineRunner init method. It's executed at the end of the system startup and works fine

谢谢

安东尼奥

这篇关于Spring Boot 延迟 Flyway 初始化循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆