javaEEday12-springAOP-快速入门--测试成功
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.aop;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Aspect//表示当前是AOP类,面向切面生效的
|
||||||
|
@Slf4j
|
||||||
|
public class TimeAspect {
|
||||||
|
|
||||||
|
//模版方法
|
||||||
|
@Around("execution(* com.inmind.service.*.*(..))")//切入点表达式(表示com.inmind.service包下的所有类下,所有方法都生效)
|
||||||
|
public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
//1.记录开始时间
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
//2.执行原始代码
|
||||||
|
Object result = joinPoint.proceed();
|
||||||
|
//3.记录结束时间,再计算
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
log.info("AOP操作--"+joinPoint.getSignature()+"方法执行耗时:{}ms",(end - start));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user