微信开发中 onShareAppMessage 分享参数用法详解
1040
2023-01-05
解决SpringCloud Feign传对象参数调用失败的问题
SpringCloud Feign传对象参数调用失败
不支持GET请求方式
使用Apache HttpClient替换Feign原生httpclient
@RequestBody接收json参数
bootstrap-local.yml
feign:
httpclient:
enabled: true
pom.xml
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("调用test\n");
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.getResuliKJIOQxaaEtResp();
log.error(internalApiException.getMessage(), internalApiException);
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());//返回500异常
response.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
return resultResp;
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~