本篇文章小编给大家分享一下解决SpringCloud Feign传对象参数调用失败的问题方法,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
SpringCloud Feign传对象参数调用失败
不支持GET请求方式
使用Apache HttpClient替换Feign原生httpclient
@RequestBody接收json参数
bootstrap-local.yml
feign: httpclient: enabled: true
pom.xml
com.netflix.feign feign-httpclient 8.18.0 org.apache.httpcomponents httpclient 4.5.3
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("调用testn"); return currentUser; } }
SpringCloud中Feign异常无法传递的问题
因为 cloud内部抛出异常不进行处理,Feign获取spring默认包装异常结果如下:
{
"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"
}
自定义的异常处理下返回状态
@Slf4j @RestControllerAdvice public class GlobalExceptionHandlerResolver { //内部服务异常处理 @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; } }
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔