@Aspect
@Slf4j
@Component
public class ServiceFilter {
@Pointcut("execution(* com.demo.Service.*(..))")
public void pointcutService() {}
@Around("pointcutService()")
public Object calCost(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = joinPoint.proceed();
long cost = System.currentTimeMillis() - startTime;
log.info("Service." + joinPoint.getSignature().getName() + " method cost: " + cost + "ms.");
return result;
}
@Before("pointcutService()")
public static void before(JoinPoint point){
log.info("Before of Service." + point.getSignature().getName() );
}
@After("pointcutService()")
public void after(JoinPoint point){
log.info("After of Service." + point.getSignature().getName() );
}
@AfterReturning("pointcutService()")
public void afterReturning(JoinPoint point){
log.info("AfterReturning of Service." + point.getSignature().getName() );
}
@AfterThrowing("pointcutService()")
public void afterThrowing(JoinPoint point){
log.info("AfterThrowing of Service." + point.getSignature().getName() );
}
}
execution的简单说明
execution(返回值 包路径.类.方法名(…))
参考文章文章地址
我只是对文章的内容做了实用的总结,想更多的了解AOP请学习原文。



