Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package anza.stock.utils; import org.aspectj.lang.annotation.Around; import org.springframework.stereotype.Component; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.AfterReturning; /** * * @author andrey_zatvornitskiy */ @Aspect @Component public class AspectLogger { public AspectLogger() { } @Pointcut("within(@org.springframework.stereotype.Controller *)") public void controller() { } @Around("controller()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); try { String className = joinPoint.getSignature().getDeclaringTypeName(); String methodName = joinPoint.getSignature().getName(); Object result = joinPoint.proceed(); long elapsedTime = System.currentTimeMillis() - start; System.out.println("Hello from aspect"); return result; } catch (IllegalArgumentException e) { throw e; } } }