AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
AOP的日志拦截类中,抛出异常:
java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
主要原因:对方法的参数使用JSON.toJSONString(args[index])转换时,有异常抛出【如果参数类型是请求和响应的http,使用JSON.toJSONString()转换会抛异常】
解决方案:将不能进行序列化的入参过滤掉,只要留下我们需要记录的入参参数记录到日志中即可

完整代码:
/**
* 从切点中解析出该切点对应的方法
* @param point point
* @throws ClassNotFoundException
* @throws IOException
* @author 洪墨水
*/
private void getRequestParams(ProceedingJoinPoint point,
RecordMessage recordMessage)
throws ClassNotFoundException, IOException
{
/* 类名 */
String targetObject = point.getTarget().getClass().getName();
/* 方法名 */
String methodName = point.getSignature().getName(); recordMessage.setTargetObject(targetObject);
recordMessage.setMethod(methodName); Object[] args = point.getArgs(); Class<?> targetClass = Class.forName(targetObject); Method[] methods = targetClass.getMethods(); StringBuilder requestBuilder = new StringBuilder(0); /**
* 遍历方法 获取能与方法名相同且请求参数个数也相同的方法
*/
for (Method method : methods)
{
if (!method.getName().equals(methodName))
{
continue;
} Class<?>[] classes = method.getParameterTypes(); if (classes.length != args.length)
{
continue;
} for (int index = 0; index < classes.length; index++)
{
// 如果参数类型是请求和响应的http,则不需要拼接【这两个参数,使用JSON.toJSONString()转换会抛异常】
if (args[index] instanceof HttpServletRequest
|| args[index] instanceof HttpServletResponse)
{
continue;
}
requestBuilder.append(args[index] == null ? ""
: JSON.toJSONString(args[index]));
} recordMessage.setRequestParames(requestBuilder.toString());
} return;
}
AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode的更多相关文章
- AOP拦截日志报错llegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
原文链接:https://my.oschina.net/mengzhang6/blog/2395893 关于一次AOP拦截入参记录日志报错的梳理总结 将服务发布到tomcat中后,观察服务的运行状态以 ...
- 使用Servlet3.0新特性asyncSupported=true时抛异常java.lang.IllegalStateException: Not supported
最近在运用Servlet3.0新特性:异步处理功能的时候出现以下了2个问题: 运行时会抛出以下两种异常: 一月 19, 2014 3:07:07 下午 org.apache.catalina.core ...
- Aop 打印参数日志时,出现参数序列化异常。It is illegal to call this method if the current request is not in asynchron
错误信息: nested exception is java.lang.IllegalStateException: It is illegal to call this method if the ...
- 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method
异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...
- Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)
使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...
- 异常java.lang.IllegalStateException的解决
在初始化viewPagerAdapter时,显示异常.从网上找了找有两类这样的问题,一种是说给一个视图设置了两个父类,如: TextView tv = new TextView();layout.ad ...
- 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- Tomcat启动之异常java.lang.IllegalStateException
严重: Exception sending context destroyed event to listener instance of class org.springframework.web. ...
随机推荐
- iOS开发自定义字体之静态字体
最后更新 2017-04-25 在iOS开发中经常会用到字体, 一般字体文件比较小的,单一的,几十k, 可以通过内置进去;如果字体文件比较多或者字体文件比较大,通常通过动态加载方式. 静态加载方式 将 ...
- UVALive 6859 Points (凸包)
Points 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/E Description http://7xjob4.com1.z ...
- Linux shell - 按时间和文件大小排序显示文件(ll)
在工作中有这样的情况,需要显示所有的文件,按照时间先后或者文件大小先后排序显示 命令:ls 1.按时间排序显示文件 test@> ll -rt 2.按文件大小排序显示文件(文件大小单位:k,M) ...
- Mybatis一对一关联查询
有两张表,老师表teacher和班级表class,一个class班级对应一个teacher,一个teacher对应一个class 需求是根据班级id查询班级信息(带老师的信息) 创建teacher和c ...
- Django的media配置与富文本编辑器使用的实例
效果预览 文章列表 添加文章 编辑文章|文章详情|删除文章 项目的基本文件 项目的Model from django.db import models # 导入富文本编辑器相关的模块 from cke ...
- 2013 AAAI: Uncorrelated Lasso
Si-Bao Chen, Chris Ding, Bin Luo and Ying Xie. Uncorrelated Lasso. AAAI, 2013. 第一作者是安徽大学陈思宝副教授. 第二作者 ...
- 架构-层-DAL:DAL
ylbtech-架构-层-DAL:DAL DAL是数据访问层的英文缩写,即为数据访问层(Data Access Layer).其功能主要是负责数据库的访问.简单地说就是实现对数据表的Select(查询 ...
- Python 是如何进行内存管理的?python 的程序会内存泄露吗?说说有没有什么方面防止或检测内存泄露?
Python GC主要使用 引用计数 来跟踪和回收垃圾.在引用计数的基础上,通过“标记-清除”解决容器对象可能产生的循环引用问题.通过分代 以空间换时间的方法提高垃圾回收效率 引用计数: 每个对象中都 ...
- SpringBoot系列:四、SpringBoot集成JPA
首先要明白的是JPA不是产品,它是一个规范. Jpa (Java Persistence API) 是 Sun 官方提出的 Java 持久化规范.它为 Java 开发人员提供了一种对象/关联映射工具来 ...
- 《图解设计模式》读书笔记5-2 decorator模式
目录 代码演示 模式的角色和类图 思路拓展 Decorator模式即装饰器模式,就是对类进行装饰,下面通过代码说明. 代码演示 代码展示的内容 有一个类StringDisplay:表示一句话,比如he ...