4. Code Example

Example 1. PerformanceAdvice

                
@Aspect
public class PerformanceAdvice {

    @Pointcut("execution(public * org.springbyexample.aspectjLoadTimeWeaving..*.*(..))")
    public void aspectjLoadTimeWeavingExamples() {
    }

    @Around("aspectjLoadTimeWeavingExamples()")
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
        final Logger logger = LoggerFactory.getLogger(pjp.getSignature().getDeclaringType());

        StopWatch sw = new StopWatch(getClass().getSimpleName());

        try {
            sw.start(pjp.getSignature().getName());

            return pjp.proceed();
        } finally {
            sw.stop();

            logger.debug(sw.prettyPrint());
        }
    }

}