|
@@ -0,0 +1,67 @@
|
|
|
+package com.management.platform.aop;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.annotation.*;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author: 吴涛涛 cuiyi@itany.com
|
|
|
+ * Date : 2019 - 08 - 30 13:59
|
|
|
+ * Description:<描述> 开启aop配置
|
|
|
+ * Version: 1.0
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Aspect
|
|
|
+@Configuration
|
|
|
+public class AopLogConfiguration {
|
|
|
+ //切入点表达式
|
|
|
+ @Pointcut("execution(public * com.management.*.service.*.*(..)) || execution(public * com.management.*.controller.*.*(..))")
|
|
|
+ public void logPointcut(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 前置通知
|
|
|
+ */
|
|
|
+ @Before("logPointcut()")
|
|
|
+ public void methodBefore(JoinPoint joinPoint){
|
|
|
+ ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
|
|
+ HttpServletRequest request = requestAttributes.getRequest();
|
|
|
+ //打印请求内容
|
|
|
+ log.info("---------------请求内容---------------");
|
|
|
+ log.info("请求地址:"+request.getRequestURL().toString());
|
|
|
+ log.info("请求方式:"+request.getMethod());
|
|
|
+ log.info("请求类方法:"+joinPoint.getSignature().getName());
|
|
|
+ log.info("请求类方法参数:"+ Arrays.toString(joinPoint.getArgs()));
|
|
|
+ log.info("---------------请求内容---------------");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 后置通知
|
|
|
+ */
|
|
|
+ @AfterReturning(returning = "o",pointcut = "logPointcut()")
|
|
|
+ public void methodAfterReturning(Object o){
|
|
|
+ log.info("===============返回内容===============");
|
|
|
+ log.info("返回的内容:"+ o.toString());
|
|
|
+ log.info("===============返回内容===============");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常通知
|
|
|
+ */
|
|
|
+ @AfterThrowing(pointcut = "logPointcut()",throwing = "e")
|
|
|
+ public void logThrowing(JoinPoint joinPoint,Throwable e){
|
|
|
+ log.info("***************抛出异常***************");
|
|
|
+
|
|
|
+ log.info("请求类方法:"+joinPoint.getSignature().getName());
|
|
|
+ log.info("异常内容:"+e);
|
|
|
+ log.info("***************抛出异常***************");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|