最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決SpringCloud Feign傳對(duì)象參數(shù)調(diào)用失敗的問(wèn)題

 更新時(shí)間:2021年06月23日 16:12:58   作者:itdragons  
這篇文章主要介紹了解決SpringCloud Feign傳對(duì)象參數(shù)調(diào)用失敗的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

SpringCloud Feign傳對(duì)象參數(shù)調(diào)用失敗

  • 不支持GET請(qǐng)求方式
  • 使用Apache HttpClient替換Feign原生httpclient
  • @RequestBody接收json參數(shù)

bootstrap-local.yml

feign:
  httpclient:
    enabled: true

pom.xml

<!-- 使用Apache HttpClient替換Feign原生httpclient -->
<dependency>
    <groupId>com.netflix.feign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>8.18.0</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>

feignClient:

@FeignClient(name = "hd-ucenter-server", fallback = SysTestServerFallbackImpl.class)
public interface SysTestServer { 
    @RequestMapping(value = "/test/test", method = RequestMethod.POST, consumes = "application/json")
    Object test(CurrentUser currentUser);
}

RestController:

@RestController
@PostMapping("/test")
public class TestController {
 
    @RequestMapping(value = "/test")
    public Object test(@RequestBody CurrentUser currentUser) {
        System.out.printf("調(diào)用test\n");
       return currentUser;
    }
}

SpringCloud中Feign異常無(wú)法傳遞的問(wèn)題

因?yàn)?cloud內(nèi)部拋出異常不進(jìn)行處理,F(xiàn)eign獲取spring默認(rèn)包裝異常結(jié)果如下:

{
"timestamp": "2017-12-27 15:01:53",
"status": 500,
"error": "Internal Server Error",
"exception": "com.keruyun.loyalty.commons.master.exception.BusinessException",
"message": "Request processing failed; nested exception is {\"code\":1000, \"message\":\"test Exception\"}",
"path": "/coupon/cloud/commercial/8469"
}

自定義的異常處理下返回狀態(tài)

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandlerResolver {
 
    //內(nèi)部服務(wù)異常處理
    @ExceptionHandler(InternalApiException.class)
    public ResultResp<?> handleGlobalException(HttpServletResponse response, InternalApiException internalApiException) {
        ResultResp<?> resultResp = internalApiException.getResultResp();
        log.error(internalApiException.getMessage(), internalApiException);
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());//返回500異常
        response.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
        return resultResp;
    }
}

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

安泽县| 泊头市| 晋州市| 塘沽区| 道孚县| 繁峙县| 白城市| 南昌县| 鄱阳县| 平南县| 古交市| 商都县| 方山县| 西盟| 建瓯市| 兴山县| 新营市| 菏泽市| 荔浦县| 和政县| 门源| 昔阳县| 永川市| 安岳县| 平阴县| 乡宁县| 蓝山县| 松原市| 广元市| 和田市| 大新县| 翼城县| 来宾市| 米易县| 武清区| 嫩江县| 平定县| 潍坊市| 澄迈县| 内江市| 独山县|