参考地址:https://stackoverflow.com/questions/38822971/spring-aop-exclude-some-classes
官方文档:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop


Example

  1. @Around("execution(* com.foo.bar.web.controller.*.*(..)) "
  2. + "&& !@annotation(com.foo.bar.util.NoLogging) "
  3. + "&& !@target(com.foo.bar.util.NoLogging)")
  4. public Object log(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
  5. // 切面逻辑
  6. }

Explanation

  • execution(* com.foo.bar.web.controller.*.*(..))

  • all methods of all classes in c.f.b.w.controller package
    —— 切点:com.foo.bar.web.controller包下所有的类和方法

  • "&& !@annotation(com.foo.bar.util.NoLogging)"

—— 排除:带有@NoLogging注解的方法

  • "&& !@target(com.foo.bar.util.NoLogging)"

—— 排除:带有@NoLogging注解的类的所有方法