无法将 Spring Boot 应用升级到 Flyway 7.0.0

2022-09-04 19:31:00

我正在尝试升级我的Spring Boot 2.3.4应用程序以使用Flyway 7.0.0(最新版本)。以前它使用的是Flyway 6.5.6。中的相关条目如下所示。build.gradle

buildscript {
  ext {
    flywayVersion = "7.0.0" // changed from 6.5.6
  }
}

plugins {
  id "org.flywaydb.flyway" version "${flywayVersion}"
}

dependencies {
  implementation "org.flywaydb:flyway-core:${flywayVersion}"
}

flyway {
  url = "jdbc:postgresql://0.0.0.0:5432/postgres"
  user = "postgres"
  password = "secret"
}

当我启动应用程序时发生以下错误,例如./gradlew bootRun


应用程序启动失败


描述:

尝试调用不存在的方法。尝试是从以下位置进行的:

org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)

以下方法不存在:

'int org.flywaydb.core.Flyway.migrate()'

该方法的类 org.flywaydb.core.Flyway 可从以下位置获得:

jar:file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar!/org/flywaydb/core/Flyway.class

类层次结构是从以下位置加载的:

org.flywaydb.core.Flyway: file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar

行动:

更正应用程序的类路径,使其包含 org.flywaydb.core.Flyway 的单个兼容版本


答案 1

基本上,请参阅菲利普对您的问题的评论。

Flyway 7.x.x 目前与 Spring Boot 2.3.4 不兼容

临时解决方案是降级到Flyway 6.5.7(最后一个6.x.x版本),直到Spring Boot 2.3.5发布。

阅读更多内容并关注此处的问题:https://github.com/spring-projects/spring-boot/issues/23514

支持 Flyway 的新配置选项:https://github.com/spring-projects/spring-boot/issues/23579


答案 2

在 Flyway 7 中,签名已更改。migrate

要使 Flyway 7.x.x 与 Spring Boot 2.3.x 配合使用,您可以提供自定义的 FlywayMigrationStrategy 实现,该实现调用正确的方法。migrate

import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.stereotype.Component;

@Component
public class FlywayMigrationStrategyImpl implements FlywayMigrationStrategy {
    @Override
    public void migrate(Flyway flyway) {
        flyway.migrate();
    }
}

推荐