问题记录:GateWay启动报错

版本:
  • SpringCloud: Hoxton SR6

  • GateWay:2.2.4 其它版本也一样(2.x)

  • SpringBoot:2.2.1

依赖:
<dependencies>
    <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-starter-consul-discoveryartifactId>
        <exclusions>
            <exclusion>
                <artifactId>jsr305artifactId>
                <groupId>com.google.code.findbugsgroupId>
            exclusion>
        exclusions>
    dependency>
    <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-starter-gatewayartifactId>
    dependency>
    <dependency>
        <groupId>org.projectlombokgroupId>
        <artifactId>lombokartifactId>
    dependency>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-devtoolsartifactId>
    dependency>
dependencies>
启动直接报错:

Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.resources.ConnectionProvider

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-30 17:35:32.552 ERROR 67984 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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.cloud.gateway.config.GatewayAutoConfiguration$NettyConfiguration.gatewayHttpClient(GatewayAutoConfiguration.java:622)

The following method did not exist:

    reactor.netty.resources.ConnectionProvider.elastic(Ljava/lang/String;Ljava/time/Duration;Ljava/time/Duration;)Lreactor/netty/resources/ConnectionProvider;

The method's class, reactor.netty.resources.ConnectionProvider, is available from the following locations:

    jar:file:/E:/warehouse/io/projectreactor/netty/reactor-netty/0.9.1.RELEASE/reactor-netty-0.9.1.RELEASE.jar!/reactor/netty/resources/ConnectionProvider.class

It was loaded from the following location:

    file:/E:/warehouse/io/projectreactor/netty/reactor-netty/0.9.1.RELEASE/reactor-netty-0.9.1.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.resources.ConnectionProvider

单独升级WebFulx和reactor-netty可以正常启动且访问正常

<dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-webfluxartifactId>
    <version>5.2.7.RELEASEversion>
dependency>
<dependency>
    <groupId>io.projectreactor.nettygroupId>
    <artifactId>reactor-nettyartifactId>
    <version>0.9.8.RELEASEversion>
dependency>

但运行过程中一直报如下错误

java.lang.NoSuchMethodError: org.springframework.http.server.reactive.ServerHttpResponse.setRawStatusCode(Ljava/lang/Integer;)Z

020-06-30 17:39:33.021 ERROR 63684 --- [ctor-http-nio-2] reactor.netty.http.server.HttpServer     : [id: 0xe544fb4b, L:/192.168.7.254:9527 - R:/192.168.7.254:61632] 

java.lang.NoSuchMethodError: org.springframework.http.server.reactive.ServerHttpResponse.setRawStatusCode(Ljava/lang/Integer;)Z
	at org.springframework.web.reactive.function.server.DefaultServerResponseBuilder$AbstractServerResponse.writeStatusAndHeaders(DefaultServerResponseBuilder.java:356) ~[spring-webflux-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.reactive.function.server.DefaultServerResponseBuilder$AbstractServerResponse.writeTo(DefaultServerResponseBuilder.java:344) ~[spring-webflux-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.write(AbstractErrorWebExceptionHandler.java:311) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.lambda$handle$2(AbstractErrorWebExceptionHandler.java:264) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:118) ~[reactor-core-3.3.0.RELEASE.jar:3.3.0.RELEASE]
	at ...

最终解决方法就是将SpringBoot升级到最新版本2.3.1,一切正常

父依赖
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-dependenciesartifactId>
    <version>2.3.1.RELEASEversion>
    <type>pomtype>
    <scope>importscope>
dependency>

你可能感兴趣的:(SpringCloud,spring,boot,gateway,java)