@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.service.*.*(..))")
public void logBefore(JoinPoint jp) {
System.out.println("Calling: " + jp.getSignature());
}
@Around("execution(* com.example.service.*.*(..))")
public Object logTime(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
Object result = pjp.proceed();
System.out.println("Took " + (System.currentTimeMillis() - start) + "ms");
return result;
}
}@Aspect, @Before, @After, @Around
Core Spring AOP annotations for injecting behaviour before, after, or around a method call — without touching the method itself.