java - 将 Flyway 4.1.2 升级到 6.4.4 导致 NoSuchMethodError: org.flywaydb.core.Flyway.getLocations()
问题描述
我一直在将 Spring 应用程序从 1.5.4 升级到 2.3.1。随后,Flyway 从 4.1.2 提升到 6.4.4。我现在面临的问题是,当一些 Flywaytests 运行时,会抛出以下异常:
java.lang.NoSuchMethodError: 'java.lang.String[] org.flywaydb.core.Flyway.getLocations()'
at org.flywaydb.test.junit.FlywayTestExecutionListener.locationsMigrationHandling(FlywayTestExecutionListener.java:313)
at org.flywaydb.test.junit.FlywayTestExecutionListener.dbResetWithAnotation(FlywayTestExecutionListener.java:272)
at org.flywaydb.test.junit.FlywayTestExecutionListener.beforeTestMethod(FlywayTestExecutionListener.java:191)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
...
这是我的 Flyway 配置:
@Configuration
public class FlywayConfig {
@Bean
public Flyway flyway(final DataSource dataSource) {
return Flyway.configure().dataSource(dataSource).load();
}
@Bean
public FlywayMigrationInitializer flywayInitializer(final Flyway flyway) {
return new FlywayMigrationInitializer(flyway, null);
}
}
此外,这是我的 build.gradle 的片段:
plugins {
id "org.springframework.boot" version "2.3.1.RELEASE"
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
...
}
dependencies {
compile group: 'org.springframework', name: 'spring-aspects'
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-actuator"
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-configuration-processor"
runtime("org.springframework.boot:spring-boot-properties-migrator")
compile 'org.springframework.data:spring-data-commons'
compile 'org.springframework.data:spring-data-jpa'
compile 'org.springframework.hateoas:spring-hateoas'
compile 'org.springframework.plugin:spring-plugin-core'
compile group: 'org.flywaydb', name: 'flyway-core'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'org.flywaydb.flyway-test-extensions', name: 'flyway-spring-test', version: '4.0.1'
...
}
解决方案
这可能是 Spring / Spring Boot 和 flyway-test-extensions 使用的 Flyway 版本不匹配。
请参阅 GitHub 上的以下问题:https ://github.com/flyway/flyway-test-extensions/issues/59
请升级org.flywaydb.flyway-test-extensions:flyway-spring-test
到(至少)的版本5.1.0
:
testCompile group: 'org.flywaydb.flyway-test-extensions', name: 'flyway-spring-test', version: '5.0.1'
推荐阅读
- c - 使用 execvp() 分离和执行命令行参数
- json - 如何使用 Groovy 去除 JSON 中的斜线
- python - 尝试将数据库中的项目放入 Tkinter 中的列表框时出错
- r - gam.vcomp 可以用于估计在具有 gaulss 家族的 GAM 中解释的部分偏差吗?
- html - 悬停时动画 2 侧边框
- parallel-processing - 为什么我会出现这种行为?
- javascript - 带有数据库承诺的javascript递归函数
- javascript - 在表单中的一定数量的字符之后向文本区域输出添加换行符
- visual-studio - 我需要用于 Visual Studio 的 XAMPP 吗?
- php - Xdebug V3 不会停止 VSCode 中的断点