打印方法名日志
This commit is contained in:
parent
07bca956f4
commit
a4758c602c
39
src/main/java/com/zhgd/xmgl/config/AsyncAspect.java
Normal file
39
src/main/java/com/zhgd/xmgl/config/AsyncAspect.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.zhgd.xmgl.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AsyncAspect {
|
||||
@Pointcut("@annotation(org.springframework.scheduling.annotation.Async)")
|
||||
public void servicePointcut() {
|
||||
}
|
||||
|
||||
@Around("servicePointcut()")
|
||||
public void doAround(ProceedingJoinPoint jointPoint) throws Throwable {
|
||||
// 获取当前访问的class类及类名
|
||||
Class<?> clazz = jointPoint.getTarget().getClass();
|
||||
String clazzName = jointPoint.getTarget().getClass().getName();
|
||||
// 获取访问的方法名
|
||||
String methodName = jointPoint.getSignature().getName();
|
||||
// 获取方法所有参数及其类型
|
||||
Object[] args = jointPoint.getArgs();
|
||||
Class[] argClz = ((MethodSignature) jointPoint.getSignature()).getParameterTypes();
|
||||
// 获取访问的方法对象
|
||||
Method method = clazz.getDeclaredMethod(methodName, argClz);
|
||||
log.info("开始执行异步方法:{}", methodName);
|
||||
// 执行目标方法
|
||||
Object proceed = jointPoint.proceed();
|
||||
log.info("执行结束异步方法:{}", methodName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,7 +21,6 @@ public class TaskAspect {
|
||||
|
||||
@Pointcut("@annotation(org.springframework.scheduling.annotation.Scheduled)")
|
||||
public void servicePointcut() {
|
||||
System.out.println("Pointcut: 不会被执行");
|
||||
}
|
||||
|
||||
@Around("servicePointcut()")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user