为了更好的追踪和查看http请求信息,包括请求状态,参数,以及响应报文,因此定义aop切面,按照一定格式打印出controller层请求信息和响应报文信息,项目日志框架为log back 案例代码如下:
package com.eno.config.aop;
import java.lang.reflect.Method;
import java.time.Duration;
import java.time.Instant;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttribu