【springCloud】feign.RetryableException: Read timed out executing GET.。的有效解決辦法

1.錯誤如下圖

在這裏插入圖片描述

2.解決辦法

錯誤提示是請求超時,那我們就把請求的時間改大不久行了,這也是網上的大多數朋友給的解決方案,在網關配置ribbon:

ribbon:
  ConnectTimeout: 60000 # 連接超時時間(ms)
  ReadTimeout: 60000 # 通信超時時間(ms)

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMillisecond: 60000 # 熔斷超時時長:60000ms

如下圖:這樣可以解決問題,但是我的依然不能解決問題,可是網上的答案給我的方向都是延長時間,於是這個bug調了整整一天,發現是我的請求返回類型出錯了,之前報的錯是:說的是json格式,如是我將兩個錯誤結合來看,跳出了思維怪圈,如果我的請求類型不對應就會引起json轉換錯誤,同時也會時間超時。

feign.codec.DecodeException: Error while extracting response for type [class com.leyou.item.pojo.SpuDetail] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `com.leyou.item.pojo.SpuDetail` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.leyou.item.pojo.SpuDetail` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1]

	at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:174)
	at feign.SynchronousMethodHandler.executeAndDecode(S

經過檢查:我的一個服務的返回的類型,與我調用的不相互匹配,如下

調用服務:所需要得到結果類型爲SpuDetail對象

  SpuDetail spuDetail = this.goodsClient.querySpuDetailBySpuId(spu.getId());

被調用的服務:返回的類型爲List。

  public ResponseEntity<List<SpuDetail>> querySpuDetailBySpuId(@PathVariable("spuId") Long spuId){

最後類型都統一成spuDetail就好了。即

  public List<SpuDetail> querySpuDetailBySpuId(@PathVariable("spuId") Long spuId)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章