Sprint AOP 打印方法执行时间。

import org.aspectj.lang.ProceedingJoinPoint;

import org.aspectj.lang.annotation.Around;

import org.aspectj.lang.annotation.Aspect;

import org.perf4j.StopWatch;

import org.perf4j.slf4j.Slf4JStopWatch;



@Aspect

public class OrderProfileAspect{



    @Around("execution(* com.karl.controller..*.*(..)) || execution(* com.karl.service.impl..*.*(..)) || execution(* com.karl.dao..*.*(..))")

    public Object profile(ProceedingJoinPoint pjp) throws Throwable {

        String tagName = pjp.getSignature().getDeclaringType().getSimpleName() + "." + pjp.getSignature().getName();

        StopWatch stopWatch = new Slf4JStopWatch(tagName);

        Object retVal = pjp.proceed();

        stopWatch.stop();

        return retVal;

    }

}

 

你可能感兴趣的:(print)