升级到2.2.4后无法运行Spring Boot应用程序:方法不存在

时间:2020-02-06 05:23:34

标签: spring-boot gradle build.gradle resttemplate

将Spring Boot版本从2.1.11升级到2.2.4后出现错误。然后我将spring-cloud-starter-openfeign从2.0.2升级到2.2.1,但这没有帮助。

以下方法不存在:

'org.springframework.boot.web.client.RestTemplateBuilder org.springframework.boot.web.client.RestTemplateBuilder.setConnectTimeout(int)'

该方法的类org.springframework.boot.web.client.RestTemplateBuilder可从以下位置获得:

jar:file:/C:/Users/a/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.2.4.RELEASE/225a4fd31156c254e3bb92adb42ee8c6de812714/spring-boot-2.2.4.RELEASE.jar!/org/springframework/boot/web/client/RestTemplateBuilder.class

它是从以下位置加载的:

file:/C:/Users/a/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.2.4.RELEASE/225a4fd31156c254e3bb92adb42ee8c6de812714/spring-boot-2.2.4.RELEASE.jar

调用该方法的尝试发生在自定义类的构造函数中

 this.restTemplate = restTemplateBuilder.setConnectTimeout(props.getConnectTimeoutMs()).setReadTimeout(props.getReadTimeoutMs()).build();

build.gradle:

buildscript {
    repositories {...
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
        classpath('gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.17.2')
        classpath('org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:2.2.1')
    }
}

plugins {
    id "org.sonarqube" version "2.6.2"
    id "com.jfrog.artifactory" version "4.6.2"
}

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.unbroken-dome.test-sets'

sourceCompatibility = 11

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Hoxton.RELEASE'
    }
}

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    exclude group: 'ch.qos.logback", module: "logback-classic'
    exclude group: 'ch.qos.logback", module: "logback-core'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('javax.xml.bind:jaxb-api:2.3.0')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.cloud:spring-cloud-starter-openfeign:2.2.1.RELEASE')
    compile('io.github.openfeign:feign-jackson:10.7.4')
    compile("org.togglz:togglz-spring-boot-starter:2.6.1.Final")
    compile('org.springframework.retry:spring-retry:1.2.2.RELEASE')
    runtime('io.micrometer:micrometer-registry-prometheus:1.3.2')
    compileOnly("org.projectlombok:lombok:1.18.6")
    annotationProcessor("org.projectlombok:lombok:1.18.6")
    compile("org.mapstruct:mapstruct:1.3.0.Final")
    annotationProcessor("org.mapstruct:mapstruct-processor:1.3.0.Final")
    compile('com.microsoft.azure:azure-servicebus:1.2.12')
    compile("io.springfox:springfox-swagger2:2.9.2")
    compile("io.springfox:springfox-swagger-ui:2.9.2")
    compile('org.apache.commons:commons-io:1.3.2')
    compile("com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.2")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.2")
    compile('org.apache.commons:commons-lang3:3.7')
    compile('commons-validator:commons-validator:1.6')
    compile('org.apache.httpcomponents:httpclient:4.5.8')
    compile('org.springframework.boot:spring-boot-starter-log4j2')
    testCompile('org.testcontainers:spock:1.12.4')
    testCompile('org.codehaus.groovy:groovy-all:2.5.8')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile("org.spockframework:spock-core:1.3-groovy-2.5")
    testCompile("org.spockframework:spock-spring:1.3-groovy-2.5")
    testCompile('nl.jqno.equalsverifier:equalsverifier:3.1.10')
    compile('com.microsoft.azure:azure:1.20.1')
    testAnnotationProcessor("org.projectlombok:lombok:1.18.6")
    testCompile('com.github.tomakehurst:wiremock:2.15.0')
    testCompile('com.github.tomjankes:wiremock-groovy:0.2.0')
    testCompile('com.rabbitmq:amqp-client:5.2.0')
}

2 个答案:

答案 0 :(得分:0)

分别查看版本2.1.112.2.4的Javadoc。较旧的版本仍使用int参数公开此方法,但已声明已弃用,应改为使用java.time.Duration

2.2.4中仍然存在接受java.time.Duration的方法,您应该改用该方法。

答案 1 :(得分:0)

似乎不推荐使用setConnectTimeout(int connectTimeout),而是添加了setConnectTimeout(Duration connectTimeout)。请尝试添加此内容