版本:
-
SpringCloud: Hoxton SR6
-
GateWay:2.2.4 其它版本也一样(2.x)
-
SpringBoot:2.2.1
依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> <exclusions> <exclusion> <artifactId>jsr305</artifactId> <groupId>com.google.code.findbugs</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> |
启动直接报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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可以正常启动且访问正常
1 2 3 4 5 6 7 8 9 10 | <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webflux</artifactId> <version>5.2.7.RELEASE</version> </dependency> <dependency> <groupId>io.projectreactor.netty</groupId> <artifactId>reactor-netty</artifactId> <version>0.9.8.RELEASE</version> </dependency> |
但运行过程中一直报如下错误
1 2 3 4 5 6 7 8 9 | 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,一切正常
父依赖
1 2 3 4 5 6 7 | <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.3.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> |