AOP案例(一)

package com.jt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RuntimeAOP {

@Around("execution(* com.jt.service..*.*(..))")
public Object around(ProceedingJoinPoint joinPoint) {
Object obj=null;
Long starttime=System.currentTimeMillis();
try {
obj=joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Long endtime=System.currentTimeMillis();
Class<?> targetclass = joinPoint.getTarget().getClass();
String methodName = joinPoint.getSignature().getName();

System.out.println("目标的对象类型:"+targetclass);
System.out.println("目标方法的名称:"+methodName);
System.out.println("RuntimeAOP[] 执行时间:"+(endtime-starttime)+"毫秒");

return obj;
}
}

上一篇:SpringBoot统计接口的耗时


下一篇:AspectJ框架使用案例