Aop 打印參很多天志時,出現參數序列化異常。It is illegal to call this method if the current request is not in asynchron

錯誤信息:java

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:
錯誤緣由:數組

joinPoint.getArgs()返回的數組中攜帶有Request(HttpServletRequest)或者Response(HttpServletResponse)對象,致使序列化異常。async

解決方案:this

//aop中獲取請求參數spa

Object[] args = joinPoint.getArgs();
Stream<?> stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.asList(args);
List<Object> logArgs = stream.filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse))).collect(Collectors.toList());
//過濾後序列化無異常
String string = JSON.toJSONString(logArgs);對象

相關文章
相關標籤/搜索