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. ...
随机推荐
- rf-idf的java实现
还存在的问题是,对于其中分词借助的库还存在问题 参考此篇链接 http://www.cnblogs.com/ywl925/archive/2013/08/26/3275878.html 具体代码部分: ...
- WinSetupFromUSB - 超简单制作多合一系统安装启动U盘的工具 (支持Win/PE/Linux启动盘)
很多同学都喜欢将电脑凌乱不堪的系统彻底重装以获得一个"全新的开始",但你会发现如今很多电脑都已经没有光驱了,因此制作一个U盘版的系统安装启动盘备用是非常必要的. 我们之前推荐过 I ...
- [git] 如何处理push失败的commit
在使用git及github时,遇到一个问题:commit了一个超过100M的大文件,然后在push时失败,然后就再也无法push了,本地大文件删除了,再commit,再push也还是提示有大文件提交. ...
- 【后台管理系统】—— Ant Design Pro组件使用(二)
一.关联表单项 - 动态增删输入框Input 封装子组件 class ParamsInputArray extends React.Component{ constructor(prop ...
- centos修改时区,同步时间
查看当前系统时区 ls -la /etc/localtime 查看支持的时区 timedatectl list-timezones # 查看所有时区 timedatectl list-timezone ...
- python-笔记(操作excel)
python操作excel,python操作excel使用xlrd.xlwt和xlutils模块,xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的.这 ...
- python -加密(MD5)
import hashlib def md5_passwd(str,salt ='aaaaa') str = str + salt m = hashlib.md5()#构造一个MD5对象 m.upda ...
- 关于一段有趣代码引出的String创建对象的解释
通常来说,我们认为hashCode不相同就为不同的对象.就这样由一段代码引发了一场讨论,代码如下: @Test public void stringCompare() { String s1 = &q ...
- Mac018--VisualBox & ubuntu 安装
一.安装虚拟机VMware 参考博客:https://blog.csdn.net/u013142781/article/details/50529030 Step1:下载ubuntu镜像 注:选择Ub ...
- linux--初识别
镜像网站 下载系统镜像 http://mirrors.163.com/ http://mirrors.sohu.com https://www.netcraft.com/ 命令大全 https://m ...