package project.developmentstudy.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect //aop를 쓰기위한 어노테이션
@Component //빈등록
public class TimeTraceAop {
@Around("execution(* project.developmentstudy..*(..))")
public Object excute(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis(); //함수에 들어가야할 로직작성
System.out.println("START: "+joinPoint.toString());
try{
return joinPoint.proceed(); //다음함수호출
} finally {
long finish = System.currentTimeMillis();
long timeMs = finish - start;
System.out.println("END: "+joinPoint.toString()+" "+timeMs+"ms");
}
}
}