无法将 Spring 启动应用程序升级到 Flyway 7.0.0

Failed to ugrade a Spring Boot app to Flyway 7.0.0

我正在尝试升级我的 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


APPLICATION FAILED TO START


Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

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

The following method did not exist:

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

The method's class, org.flywaydb.core.Flyway, is available from the following locations:

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

The class hierarchy was loaded from the following locations:

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

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.flywaydb.core.Flyway

基本上,请参阅 Philip 对您的问题的评论。

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

降级到 Flyway 6.5.7 有效。

在 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();
    }
}