Spring AOP has a method-level tracer called CustomizableTraceInterceptor. Using Spring\'s XML configuration approach, one would set up this tracer like so:
Just wanted to add to AdrienC's response. I'll use the point expression to reference an aggregated point, more clearer separation, imho
package org.example;
@Configuration
@EnableAspectJAutoProxy
@Aspect
public class AopConfiguration {
/** Pointcut for execution of methods on {@link Service} annotation */
@Pointcut("execution(public * (@org.springframework.stereotype.Service org.example..*).*(..))")
public void serviceAnnotation() { }
/** Pointcut for execution of methods on {@link Repository} annotation */
@Pointcut("execution(public * (@org.springframework.stereotype.Repository org.example..*).*(..))")
public void repositoryAnnotation() {}
/** Pointcut for execution of methods on {@link JpaRepository} interfaces */
@Pointcut("execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))")
public void jpaRepository() {}
@Pointcut("serviceAnnotation() || repositoryAnnotation() || jpaRepository()")
public void performanceMonitor() {}
@Bean
public PerformanceMonitorInterceptor performanceMonitorInterceptor() {
return new PerformanceMonitorInterceptor(true);
}
@Bean
public Advisor performanceMonitorAdvisor() {
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression("org.example.AopConfiguration.performanceMonitor()");
return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor());
}
}