使用的Spring Boot版本是2.0.0.RELEASE
,Spring Cloud版本是Finchley.M8
请求返回200仍处于Pending状态
项目中使用gateway时出现一些问题,部分请求已经正确返回200了,但是仍然显示在Pending。有时是ajax请求,有时是一些静态资源css,js之类的。
经过查找在GitHub的spring-cloud-gateway的issues中有人提过此bug。
解决方法是将spring-cloud-starter-gateway
的包中reactor-netty
升级到0.7.7.RELEASE及以上版本就可以。
Spring Boot2.0.0对应的reactor-netty
版本是0.7.5.RELEASE
,升级到2.0.2应该就可以了。但是由于没找到Spring Boot2.0.2对应的Spring Cloud版本,所以现在将Spring Boot升级到2.0.3.RELEASE
,Spring Cloud升级到Finchley.RELEASE
。此时的reactor-netty
版本是0.7.8.RELEASE
.
静态文件,部分请求返回NPE
Spring Boot升级到2.0.3后部分Ajax请求和静态资源时出现NPE,但将这个链接http://localhost:10003/api/admin/plugins/util.js使用浏览器打开可以正常得到js的
2019-05-31 16:00:28.038 [reactor-http-nio-5] ERROR o.s.b.a.w.r.error.DefaultErrorWebExceptionHandler - Failed to handle request [GET http://localhost:10003/api/admin/plugins/util.js]
java.lang.NullPointerException: null
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
at org.springframework.cloud.gateway.filter.NettyRoutingFilter.lambda$filter$3(NettyRoutingFilter.java:117)
官方issues上有类似的bug提出 https://github.com/spring-cloud/spring-cloud-gateway/issues/392
查看spring-cloud-starter-gateway
的依赖,虽然版本是2.0.3,但是spring-cloud-gateway-core
还是2.0.0
解决方法为升级 spring-cloud-gateway-core 依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.0.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-core</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
参考