It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncS

场景

提示信息1:
It is illegal to call this method if the current request is not in asynchronous mode (i.e.
isAsyncStarted() returns false)
提示信息2:
Request processing failed; nested exception is com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.58, class

这个一般出现序列化的时候。例如拦截器,打印request。

logger.info("request:{}",JSON.toJSONString(request));

解决方案

不直接序列化整个request,而是拿出其中需要的字段进行打印即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是由于在使用`@RequestBody`注解时,请求体为空导致的。在Spring MVC中,`@RequestBody`注解用于将HTTP请求正文绑定到方法参数上。如果请求正文为空,则会抛出`MissingServletRequestParameterException`异常,错误消息为“Required request body is missing”。以下是解决此问题的一些方法: 1. 确保请求正文不为空。可以使用Postman等工具检查请求正文是否正确。 2. 确保使用`@RequestBody`注解的方法的Content-Type与请求正文的Content-Type匹配。例如,如果请求正文是JSON格式,则Content-Type应为application/json。 3. 确保使用`@RequestBody`注解的方法的参数类型正确。例如,如果请求正文是JSON格式,则参数类型应为Java对象,该对象的属性应该与JSON对象的属性相匹配。 以下是一个使用`RequestResponseBodyMethodProcessor`处理`@RequestBody`注解的示例: ```java @RestController public class MyController { @Autowired private RequestResponseBodyMethodProcessor processor; @PostMapping("/myEndpoint") public ResponseEntity<?> myEndpoint(HttpServletRequest request, HttpServletResponse response) throws Exception { MethodParameter parameter = new MethodParameter(MyController.class.getMethod("myEndpoint", HttpServletRequest.class, HttpServletResponse.class), 0); Object requestBody = processor.resolveArgument(parameter, null, request, response); // 处理请求正文 return ResponseEntity.ok().build(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值