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

huangapple go评论75阅读模式
英文:

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" // 从 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 版本。

英文:

I'm trying to upgrade my Spring Boot 2.3.4 app to use Flyway 7.0.0 (the latest version). Previously it was using Flyway 6.5.6. The relevant entries in build.gradle are shown below.

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"
}

The following error occurs when I start the app e.g. with ./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

答案1

得分: 11

基本上,查看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

英文:

Basically, see Philip's comment on your question.

Flyway 7.x.x is not currently compatible with Spring Boot 2.3.4

Temporary solution is to just downgrade to Flyway 6.5.7 (the last 6.x.x version) until Spring Boot 2.3.5 is released.

Read more and follow the issue here: https://github.com/spring-projects/spring-boot/issues/23514

Support for Flyway's new configuration options: https://github.com/spring-projects/spring-boot/issues/23579

答案2

得分: 9

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

In Flyway 7 the signature of migrate changed.

To get Flyway 7.x.x working with Spring Boot 2.3.x you can provide a custom FlywayMigrationStrategy implementation, which calls the the right migrate method.

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

答案3

得分: 1

降级至 Flyway 6.5.7 可行。

英文:

downgrade to Flyway 6.5.7 works.

huangapple
  • 本文由 发表于 2020年10月2日 22:45:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/64173564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定