spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.51k stars 3.31k forks source link

java.lang.NoSuchMethodError: org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient.<init>(Ljava/util/function/Consumer;)V #1065

Closed yjwfn closed 5 years ago

yjwfn commented 5 years ago

hi , I am use spring-cloud-gateay in a service mesh, when start it I have get a error:

Caused by: java.lang.NoSuchMethodError: org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient.<init>(Ljava/util/function/Consumer;)V

Dependencies

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ gateway ---
[INFO] cn.rctech.egg:gateway:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:5.1.6.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-aop:jar:5.1.6.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-beans:jar:5.1.6.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-expression:jar:5.1.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.springframework:spring-core:jar:5.1.6.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- org.springframework.cloud:spring-cloud-starter-gateway:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-gateway-core:jar:2.0.3.RELEASE:compile
[INFO] |  |  \- io.projectreactor.addons:reactor-extra:jar:3.1.6.RELEASE:compile
[INFO] |  |     \- io.projectreactor:reactor-core:jar:3.1.8.RELEASE:compile
[INFO] |  |        \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] |  \- org.springframework.boot:spring-boot-starter-webflux:jar:2.0.3.RELEASE:compile
[INFO] |     +- org.springframework.boot:spring-boot-starter-json:jar:2.0.3.RELEASE:compile
[INFO] |     |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile
[INFO] |     |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.7:compile
[INFO] |     |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.7:compile
[INFO] |     |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.7:compile
[INFO] |     |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.7:compile
[INFO] |     +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.0.3.RELEASE:compile
[INFO] |     |  \- io.projectreactor.ipc:reactor-netty:jar:0.7.8.RELEASE:compile
[INFO] |     |     +- io.netty:netty-codec-http:jar:4.1.25.Final:compile
[INFO] |     |     |  \- io.netty:netty-codec:jar:4.1.25.Final:compile
[INFO] |     |     +- io.netty:netty-handler:jar:4.1.25.Final:compile
[INFO] |     |     |  +- io.netty:netty-buffer:jar:4.1.25.Final:compile
[INFO] |     |     |  \- io.netty:netty-transport:jar:4.1.25.Final:compile
[INFO] |     |     |     \- io.netty:netty-resolver:jar:4.1.25.Final:compile
[INFO] |     |     +- io.netty:netty-handler-proxy:jar:4.1.25.Final:compile
[INFO] |     |     |  \- io.netty:netty-codec-socks:jar:4.1.25.Final:compile
[INFO] |     |     \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.25.Final:compile
[INFO] |     |        +- io.netty:netty-common:jar:4.1.25.Final:compile
[INFO] |     |        \- io.netty:netty-transport-native-unix-common:jar:4.1.25.Final:compile
[INFO] |     +- org.hibernate.validator:hibernate-validator:jar:6.0.10.Final:compile
[INFO] |     |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |     |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |     |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |     +- org.springframework:spring-web:jar:5.1.6.RELEASE:compile
[INFO] |     +- org.springframework:spring-webflux:jar:5.1.6.RELEASE:compile
[INFO] |     \- org.synchronoss.cloud:nio-multipart-parser:jar:1.1.0:compile
[INFO] |        \- org.synchronoss.cloud:nio-stream-storage:jar:1.1.3:compile
[INFO] +- com.alibaba.boot:nacos-config-spring-boot-starter:jar:0.2.1:compile
[INFO] |  +- com.alibaba.nacos:nacos-spring-context:jar:0.2.3-RC1:compile
[INFO] |  |  +- com.alibaba.nacos:nacos-client:jar:1.0.0:compile
[INFO] |  |  |  +- com.alibaba.nacos:nacos-common:jar:1.0.0:compile
[INFO] |  |  |  |  +- commons-io:commons-io:jar:2.6:compile
[INFO] |  |  |  |  \- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] |  |  |  +- com.alibaba.nacos:nacos-api:jar:1.0.0:compile
[INFO] |  |  |  |  \- com.alibaba:fastjson:jar:1.2.47:compile
[INFO] |  |  |  +- com.google.guava:guava:jar:23.0:compile
[INFO] |  |  |  |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  |  |  |  +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] |  |  |  |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  |  |  |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] |  |  |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
[INFO] |  |  |  \- io.prometheus:simpleclient:jar:0.5.0:compile
[INFO] |  |  \- com.alibaba.spring:spring-context-support:jar:1.0.1:compile
[INFO] |  +- com.alibaba.boot:nacos-config-spring-boot-autoconfigure:jar:0.2.1:compile
[INFO] |  \- com.alibaba.boot:nacos-spring-boot-base:jar:0.2.1:compile
[INFO] +- com.alibaba.boot:nacos-discovery-spring-boot-starter:jar:0.2.1:compile
[INFO] |  \- com.alibaba.boot:nacos-discovery-spring-boot-autoconfigure:jar:0.2.1:compile
[INFO] \- org.springframework.cloud:spring-cloud-starter:jar:2.0.3.RELEASE:compile
[INFO]    +- org.springframework.cloud:spring-cloud-context:jar:2.0.3.RELEASE:compile
[INFO]    |  \- org.springframework.security:spring-security-crypto:jar:5.0.6.RELEASE:compile
[INFO]    +- org.springframework.cloud:spring-cloud-commons:jar:2.0.3.RELEASE:compile
[INFO]    \- org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
[INFO]       \- org.bouncycastle:bcpkix-jdk15on:jar:1.60:compile
[INFO]          \- org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[
spencergibb commented 5 years ago

This is almost always caused by a mismatched version. Can you show your pom?

yjwfn commented 5 years ago

This is almost always caused by a mismatched version. Can you show your pom?

Yes , I seen org.springframework.boot:spring-boot-starter-webflux:2.0.3.RELEASE dependency onorg.springframework:spring-webflux:5.1.6.RELEASE , but org.springframework:spring-webflux:5.1.6.RELEASE incompatible with org.springframework.cloud:spring-cloud-gateway-core:2.0.3.RELEASE

yjwfn commented 5 years ago

This is almost always caused by a mismatched version. Can you show your pom?

Parent dependencies

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

    <groupId>cn.rctech.egg</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>pom</packaging>
    <properties>
        <java.version>1.8</java.version>
        <jackson.version>2.9.7</jackson.version>
        <dubbo.version>2.7.1</dubbo.version>
        <spring-cloud.version>Finchley.SR3</spring-cloud.version>
        <spring.version>5.1.6.RELEASE</spring.version>
        <nacos.boot.version>0.2.1</nacos.boot.version>
        <nacos.client.version>1.0.0</nacos.client.version>
        <mysql.version>8.0.13</mysql.version>

    </properties>

    <dependencyManagement>
        <!-- 声明一些常用的依赖项 -->

        <dependencies>
            <dependency>
                <groupId>cn.rctech.egg</groupId>
                <artifactId>common</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>

            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>1.2.3</version>
            </dependency>

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>

            <dependency>
                <groupId>com.auth0</groupId>
                <artifactId>java-jwt</artifactId>
                <version>3.5.0</version>
            </dependency>

            <dependency>
                <groupId>com.yunpian.sdk</groupId>
                <artifactId>yunpian-java-sdk</artifactId>
                <version>1.2.6</version>
            </dependency>

            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.2</version>
            </dependency>

            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>1.9.3</version>
            </dependency>

            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>23.0</version>
            </dependency>

            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.6</version>
            </dependency>

            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.10</version>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jackson.version}</version>
            </dependency>

            <dependency>
                <!-- Note: core-annotations version x.y.0 is generally compatible with
                     (identical to) version x.y.1, x.y.2, etc. -->
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${jackson.version}</version>
            </dependency>

            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
                <version>1.2.10</version>
            </dependency>

            <dependency>
                <groupId>net.logstash.logback</groupId>
                <artifactId>logstash-logback-encoder</artifactId>
                <version>5.3</version>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter</artifactId>
                <version>2.0.3.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba.boot</groupId>
                <artifactId>nacos-config-spring-boot-starter</artifactId>
                <version>${nacos.boot.version}</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba.boot</groupId>
                <artifactId>nacos-discovery-spring-boot-starter</artifactId>
                <version>${nacos.boot.version}</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
                <version>${nacos.client.version}</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-spring-context</artifactId>
                <version>0.2.3-RC1</version>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>${dubbo.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo</artifactId>
                <version>${dubbo.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-spring-boot-autoconfigure</artifactId>
                <version>${dubbo.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-registry-nacos</artifactId>
                <version>${dubbo.version}</version>
            </dependency>

        </dependencies>

    </dependencyManagement>

Service dependencies

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>nacos-config-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>nacos-discovery-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency> 
    </dependencies>
yjwfn commented 5 years ago

The org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient of org.springframework:spring-webflux:5.1.6.RELEASE is :

public class ReactorNettyWebSocketClient implements WebSocketClient {

    private static final Log logger = LogFactory.getLog(ReactorNettyWebSocketClient.class);

    private final HttpClient httpClient;

    /**
     * Default constructor.
     */
    public ReactorNettyWebSocketClient() {
        this(HttpClient.create());
    }

    /**
     * Constructor that accepts an existing {@link HttpClient} builder.
     * @since 5.1
     */
    public ReactorNettyWebSocketClient(HttpClient httpClient) {
        Assert.notNull(httpClient, "HttpClient is required");
        this.httpClient = httpClient;
    }
  .....
}

It's second constructor above need a HttpClient object to instance, that mismatched with org/springframework/cloud/gateway/config/GatewayAutoConfiguration$NettyConfiguration.class.


@Bean
public ReactorNettyWebSocketClient reactorNettyWebSocketClient(@Qualifier("nettyClientOptions") Consumer<? super HttpClientOptions.Builder> options) {
    return new ReactorNettyWebSocketClient(options);
}
OlgaMaciaszek commented 5 years ago

Hi @yjwfn Could you please try it out with Spring Boot Starter 2.0.9.RELEASE and let us know if the problem appears also with that setup?

yjwfn commented 5 years ago

Hi @yjwfn Could you please try it out with Spring Boot Starter 2.0.9.RELEASE and let us know if the problem appears also with that setup?

I upgrade to Spring Boot 2.1.5.RELEASE and Spring Cloud Greenwich.RELEASE already , it's working fine.

This problem I don't have any idea to resolve it, I think it is compatibility problem.

OlgaMaciaszek commented 5 years ago

yes, but in your issue, you were using the most recent Finchley version with a Spring Boot 2.0.x version that was 6 minors behind the current one. Everything should work on Finchley + Spring Boot 2.0.x, so that's why I've suggested you try out with a more recent 2.0.x Boot (2.0.9.RELEASE).

yjwfn commented 5 years ago

@OlgaMaciaszek

After try out with Spring Boot Starter 2.0.9.RELEASE the console show :

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient.<init>(Ljava/util/function/Consumer;)V but it does not exist. Its class, org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient, is available from the following locations:

    jar:file:/Users/hb/.m2/repository/org/springframework/spring-webflux/5.1.6.RELEASE/spring-webflux-5.1.6.RELEASE.jar!/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.class

It was loaded from the following location:

    file:/Users/hb/.m2/repository/org/springframework/spring-webflux/5.1.6.RELEASE/spring-webflux-5.1.6.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient
spencergibb commented 5 years ago

You've upgraded spring to 5.1.x with boot 2.0.x which isn't compatible. You'd need to use spring 5.0.x