Spring Cloud Gateway Request Pending

使用的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

springcloud版本依賴

解決方法爲升級 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>

參考

https://www.cnblogs.com/dalaoyang/p/10521534.html

http://xiaoqiangge.com/aritcle/1545889008833.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章