spring-boot - 带有 Spring Boot 和 gradle 的 flyway--org.flywaydb.core.Flyway : method <init>()V not found

标签 spring-boot gradle flyway nosuchmethoderror

我有一个带有 gradle 和使用 postgres db 的 Spring Boot 项目。我想通过使用 flyway 进行数据库迁移来进行测试。我面临以下错误。我的 build.gradle 和 application.properties 也在下面给出。请帮我解决这个错误。我相信这与设置有关,但与实际代码无关。

错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123) ~[spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:300) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1082) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1071) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at com.ford.mach1mldb.AccessingDataRestApplication.main(AccessingDataRestApplication.java:10) [main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    ... 20 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$SpringBootFlyway.<init>(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$SpringBootFlyway.<init>(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:130) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9.CGLIB$flyway$0(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9$$FastClassBySpringCGLIB$$b74dfec1.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9.flyway(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_221]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_221]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_221]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_221]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    ... 21 common frames omitted

构建.gradle:
buildscript {
    ext {
        springBootVersion = '1.5.22.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
        maven {
         url "https://plugins.gradle.org/m2/"
      }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

repositories {
    mavenCentral()
}
dependencies {

    compile( 'org.springframework.boot:spring-boot-starter-data-rest' )
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile files('./lib/postgresql-42.2.8.jar') 
    compile group: 'org.flywaydb', name: 'flyway-core', version: '6.0.1'
    compile group: 'javax.validation', name: 'validation-api', version: '2.0.0.Final'   
    compile group: 'org.springframework.ws', name: 'spring-ws-support'
    compile('org.springframework:spring-context-support')
    compile "org.apache.httpcomponents:httpmime:4.2.3"
    compile "org.apache.httpcomponents:httpclient:4.5.2"
    compile "org.apache.httpcomponents:httpcore:4.4.5"
    compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5' 
}

dependencyManagement {
    imports {
        mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:1.4.1.RELEASE"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.SR5"
    }
}


应用程序属性:
spring.jpa.show-sql=true

#postgress
spring.datasource.url=jdbc:postgresql://xxx/xxx
spring.datasource.username=xxx
spring.datasource.password=
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect


flyway.baseline-on-migrate=true 

最佳答案

是的,我还将我的 Flyway 版本从 5.2.4 升级到 7.0.0 并捕获相同的错误。
为了解决这个问题,我将 flyway 版本降级到 6.5.0,它现在可以工作了!

关于spring-boot - 带有 Spring Boot 和 gradle 的 flyway--org.flywaydb.core.Flyway : method <init>()V not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58119945/

相关文章:

java - Spring Boot 2 是否支持 Java 10?

docker - 如何在没有 JAR 的情况下为 Spring Boot 应用程序构建 Docker 镜像

c# - Unity - CommandInvokationFailure : Gradle build failed

java - 如何添加 Flyway 依赖项并构建原生图像 Quarkus java.lang.ClassNotFoundException : org. jboss.vfs.VirtualFileFilter

postgresql - 强制失败的 mvn flyway :migrate to skip failed schema migration, 并尝试执行下一个模式

javascript - 如何使用 StreamSaver.js 从 Axios 消费下载流?

java - 返回在 REST Controller 中包装 S3Object.getObjectContent() 的 ResponseEntity<InputStreamResource> 是否安全?

gradle - 多次运行 gradle 任务

java - 403 禁止使用 Oracle 存储库中的 jdbc 驱动程序

java - 通过 Spring Boot 仅在 Release 内(仅最后更新文件)进行可重复迁移