It is illegal to call this method if the current request is not in asynchron

别再到处找了!GWAS数据下载保姆级指南:从IEU、FinnGen到UK Biobank一站搞定 本文提供GWAS数据下载的全面指南,涵盖IEU OpenGWAS、FinnGen、UK Biobank等五大核心数据库的获取策略。从数据库选型到实战操作,详细解析数据搜索、下载、预处理全流程,帮助科研人员高效获取GWAS数据,特别适合初学者快速上手。 阅读详情

切面报错写法:

/*
@auther aa

@create_date 2019-12-24 15:15

@Desc 接口请求日志切面

**/

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class WebLogAcpect {
    protected static final Logger logger = LoggerFactory.getLogger(WebLogAcpect.class);

    /**
     * 定义切入点
     * */
    @Pointcut("execution(* com.smcv.xyx.partOrder.manage.controller.view..*.*(..))")
    public void webLog(){}

    /**
     * 前置通知
     * */
    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint)throws Exception{
        //接收到请求,打印请求内容
        ServletRequestAttributes attributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //记录请求内容
        logger.info("-------------log print start--------");
        logger.info("请求接口名:{},请求方式:{}",request.getRequestURI().toString(),request.getMethod());
//报错位置在此下方
//报错位置在此下方
//报错位置在此下方
        logger.info("请求参数:{}",JSON.toJSONString(joinPoint.getArgs()));

    }

    @AfterReturning(returning="ret",pointcut = "webLog()")
    public void doAfterReturning(Object ret)throws Exception{
        ServletRequestAttributes attributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //接收到响应,打印请求内容
        logger.info("请求接口:{}的响应为:{}",request.getRequestURI(),JSON.toJSONString(ret));
        logger.info("-------------log print end--------");

    }

}

因为:当请求中带有ServletRequest或ServletResponse时无法进行序列号,因而报错

【解决方式】

/*
@auther aa

@create_date 2019-12-24 15:15

@Desc 接口请求日志切面

**/

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class WebLogAcpect {
    protected static final Logger logger = LoggerFactory.getLogger(WebLogAcpect.class);

    /**
     * 定义切入点
     * */
    @Pointcut("execution(* com.smcv.xyx.partOrder.manage.controller.view..*.*(..))")
    public void webLog(){}

    /**
     * 前置通知
     * */
    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint)  {
        Object[] args = joinPoint.getArgs();
        Object[] arguments = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            if (args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof MultipartFile) {
                //ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
                //ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
                continue;
            }
            arguments[i] = args[i];
        }
        String paramter = "";
        if (arguments != null) {
            try {
                paramter = JSONObject.toJSONString(arguments);
            } catch (Exception e) {
                paramter = arguments.toString();
            }
        }
        logger.info("请求接口名:{}", joinPoint.getSignature().getName());
        logger.info("请求参数:{}", paramter);
    }

    @AfterReturning(returning="ret",pointcut = "webLog()")
    public void doAfterReturning(Object ret)throws Exception{
        ServletRequestAttributes attributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //接收到响应,打印请求内容
        logger.info("请求接口:{}的响应为:{}",request.getRequestURI(),JSON.toJSONString(ret));
        logger.info("-------------log print end--------");

    }

}

 

扫地机的CPU只要二十多块?2024第二拆来了 昨天还说到这个机器人的故障,经小鱼拆机后测试和后台网友留言确认,不是防跌落问题,是轮子故障,这个轮子不会动,轮子上有一个限位开关检测机器人是否离开地面的,测试的时候也没有误触发,所以电机存在故障,后面拆电机的时候再检查。最后再留下一个疑问,这个机器人的回充没有用红外管,机器人是如何识别基站进行返回充电的(因为只买了本体,没买充电桩,不确定充电桩的形状,是不是利用点云识别不确定)懂的请留言。全志的R16,封装是 BGA282,那这个板子至少是4层板,小鱼盲猜 6 层板,知道的小伙伴欢迎留言。 阅读详情

相关推荐

✨使用 vLLM + Docker 部署 Qwen3-Embedding-8B 并实现高效文本向量生成(附 `curl` 测试)

本文介绍了如何使用 vLLM 和 Docker 部署 Qwen3-Embedding-8B 嵌入模型服务,并通过标准 OpenAI 兼容接口进行调用和结果解析。如果你在部署中遇到任何问题,欢迎留言讨论!

用大模型重构生活:猫奴程序员的AI智能日常记录 6238

It is illegal to call this method if the current request is not in asynchronous mode

nested exception is java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)] with root cause M...

3508

Applied Energy期刊小白论文投稿模板-流程经验分享

Applied Energy期刊小白论文投稿模板-流程经验分享,Elsevier期刊(爱思唯尔)投稿流程

zzu_Flyer的博客 4万+

toJSON抛出异常It is illegal to call this method if the current request is not in asynchronous mode

将不能进行序列化的入参对象过滤掉,只要留下我们所需数据即可。对于这里的joinPoint,我们只需要去除request和response对象即可。在使用AOP实现日志记录功能时,用到了JSON.toJSON()将joinPoint.getArgs()数据转换为Json串,运行时抛出异常。抛出该异常的主要原因是JSON.toJSON()转换数据时要求入参必须是。数据,如果入参不能序列化,则会抛出上述异常。

swlimuhao的博客 2460

CS231n+assignment2(一)

cs231n作业二详解+代码

qq_56551150的博客 2411

利用eds editor生成CANOPEN 设备eds文件

通过以上步骤,您可以根据实际设备的功能特性,自动生成一份符合CANopen协议标准的电子数据表(EDS文件),该文件可以被上位机软件或其他CANopen主站设备用于识别、配置和控制您的CANopen从站设备。使用CANopen EDS Editor生成CANOPEN设备的EDS文件是一个系统化的过程,它涉及将设备的具体技术参数和功能映射到CANopen规范定义的对象字典中。

weixin_38604759的博客 6458

切面打印日志时,参数序列化异常。It is illegal to call this method if the current request is not in asynchron ——————

1.AOP的日志拦截类中,抛出异常: 2.代码如下: package com.jimulian.iwuxi.common.aop; import com.alibaba.fastjson.JSON; import com.jimulian.iwuxi.common.annotation.OptLogAno; import com.jimulian.iwuxi.mapper.OptLogMapper; import com.jimulian.iwuxi.pojo.OptLog; import com.j

suixinsuoyu12519的专栏 574

ComfyUI安装包运行前准备:增加虚拟内存

在Windows系统中,虚拟内存是一种重要的系统资源管理机制,它主要通过将硬盘空间用作内存来扩展系统的可用内存容量。以下是虚拟内存的主要作用: 1. 扩展物理内存容量 当物理内存(RAM)不足时,系统会将一部分数据从内存转移到硬盘上的虚拟内存区域(也称为“分页文件”或“交换文件”)。这样可以为正在运行的程序提供额外的“内存空间”,确保系统能够继续运行,而不会因为内存不足而崩溃。 2. 提高系统稳定性 虚拟内存为系统提供了一个缓冲区。如果没有虚拟内存...

聚梦小课堂 1万+

每日解惑:It is illegal to call this method if the current request is not in asynchron

项目场景: 提示:这里简述项目相关背景: 例如:项目场景:示例:通过蓝牙芯片(HC-05)与手机 APP 通信,每隔 5s 传输一批传感器数据(不是很大) 问题描述: 提示:这里描述项目中遇到的问题: 例如:数据传输过程中数据不时出现丢失的情况,偶尔会丢失一部分数据 APP 中接收数据代码: @Override public void run() { bytes = mmInStream.read(buffer); mHandler.obta

qq_33331448的博客 4382

MathType 7.4保姆级安装教程:从下载到Word/WPS完美加载(附常见问题解决)

本文提供MathType 7.4的详细安装教程,涵盖从下载到Word/WPS完美加载的全过程,并附常见问题解决方案。特别针对科研写作中的公式编辑需求,介绍如何避免安装陷阱、配置Office集成及高效排版技巧,帮助用户快速掌握这一公式编辑神器。

weixin_29200741的博客 4357

手把手教你学Simulink--基于电能质量与无功补偿的场景实例:统一电能质量调节器(UPQC)的联合控制仿真

在现代电力系统中,电能质量问题有源电力滤波器(APF)→ 治理谐波与无功动态电压恢复器(DVR)→ 补偿电压暂降/暂升静止无功发生器(SVG)→ 无功补偿与电压支撑而统一电能质量调节器(Unified Power Quality Conditioner, UPQC)是一种集串联补偿与并联补偿于一体的全能型电能质量治理装置✅ 电压类问题:暂降、暂升、不平衡、闪变✅ 电流类问题:谐波、无功、三相不平衡✅ 实现双向有功交换(储能型)串联单元(DVR功能):串联于线路,控制电源侧电压质量并联单元。

MHD0815的博客 237

切面打印日志时,参数序列化异常。It is illegal to call this method if the current request is not in asynchron

切面打印日志时,参数序列化异常 异常信息:It is illegal to call this method if the current request is not in asynchron 原因 joinPoint.getArgs()返回的数组中携带有Request或者Response对象,导致序列化异常 解决 Object[] args = joinPoint.getArgs(); ...

hellodakee的博客 1万+

基于咸鱼最新九宫格图标验证码的语义增强模型识别

本文探讨了破解复杂验证码的技术思路,重点分析了某平台的九宫格验证码应对策略。作者提出通过图像语义抽取和增强技术来扩充数据集:先采集少量真实样本,利用形态学操作进行前增强生成变形图像,再通过叠加背景噪声进行后增强。同时强调真实数据集的重要性,建议采用真实+生成数据的混合训练方法。实验表明该方法可使模型准确率达到95%以上,但作者特别声明本文仅供技术研究,严禁用于非法用途。

码王吴彦祖的博客 601

Aop 打印参数日志时,出现参数序列化异常。It is illegal to call this method if the current request is not in asynchron

Aop 打印参数日志时,出现参数序列化异常。It is illegal to call this method if the current request is not in asynchron

w36680130的博客 665

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

SpringBoot 上传文件记录日志报错:It is illegal to call this method if the current request is not in asynchronou

springboot 上传文件记录日志是报错It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false) 原因,因为Object[] args = joinPoint.getArgs();会得到多余的ServletR...

子冰吖的博客 7303

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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

源头 package jane.servlet; import java.io.IOException; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import

入梦镜 2075

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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 ve

enthan809882的博客 2304

AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current reque...

AOP的日志拦截类中,抛出异常: java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode 主要原因:对方法的参数使用JSON.toJSONString(args[index])转换时,有异常抛...

weixin_30596165的博客 3069

How to use Asynchronous Servlets to improve perfor

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34029949的博客 142

java.lang.IllegalStateException: It is illegal to call this method if the current request is not in

package com.example.zhangwenbo.demo.web.servlet; import org.springframework.http.HttpRequest; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.annotat...

张文波的博客 2539

python学习笔记(二)

网络编程相关知识 Python Internet 模块 以下列出了 Python 网络编程的一些重要模块: 协议 功能用处 端口号 Python 模块 HTTP 网页访问 80 httplib, urllib, xmlrpclib NNTP 阅读和张贴新闻文章,俗称为"帖子" 119 nntplib FTP 文件传输 20 ftplib, urllib SMTP 发送邮件 25 smtplib P...

hbn1326317071的博客 183

AOP拦截日志报错llegalStateException: It is illegal to call this method if the current request is not in as...

原文链接:https://my.oschina.net/mengzhang6/blog/2395893 关于一次AOP拦截入参记录日志报错的梳理总结 将服务发布到tomcat中后,观察服务的运行状态以及日志记录状况; 发现有如下一个问题: 2018-10-31 16:20:10,701 [] INFO aspect.PayMethodLogAspectJ - rest 请求开始{154...

weixin_30555753的博客 263

Java It is illegal to call this method if the current request is not in asynchronou

废话不多说,一针见血,狠不狠你说了算!! public static Object filterParams(Object object){ if(object instanceof HttpServletRequest){ object = "请求格式为Request类型,实例化失败,已经转换为字符串:("+object.toString()+")"; } if(object instanceof HttpServletResponse){ obje

Tongyao 686
上一篇: swagger忽略显示字段
下一篇: Unable to find a single main class from the following candidates
芬芳酩酊
博客等级 码龄10年 35粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值