带有“ @target”的Spring AOP切入点不起作用,因为无法访问当前调用

时间:2018-12-11 12:25:42

标签: spring-aop

我正在尝试使切入点工作。

此切入点有效:

@Around("execution(public * my.package..*ClassSuffix.*(..))")

但是此切入点没有:

@Around("execution(public * my.package..*ClassSuffix.*(..)) && !@target(my.package.NoLogging)")

例外是

DEBUG o.s.aop.aspectj.AspectJExpressionPointcut - Could not access current invocation - matching with limited context: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress, and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor!
DEBUG o.s.aop.aspectj.AspectJExpressionPointcut - Failed to evaluate join point for arguments [] - falling back to non-match
java.lang.NullPointerException: null
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.visit(ShadowMatchImpl.java:195)
        at org.aspectj.weaver.ast.HasAnnotation.accept(HasAnnotation.java:31)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.matches(ShadowMatchImpl.java:132)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.visit(ShadowMatchImpl.java:163)
        at org.aspectj.weaver.ast.Not.accept(Not.java:26)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.matches(ShadowMatchImpl.java:132)
        at org.aspectj.weaver.reflect.ShadowMatchImpl.matchesJoinPoint(ShadowMatchImpl.java:87)
        at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:357)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at my.package.FooClassSuffix$$EnhancerBySpringCGLIB$$e7bc07ac.doSomething(<generated>)

似乎更复杂的切入点需要一定的上下文,并且ExposeInvocationInterceptor#invoke(..)在某个时间点被调用,但由于ExposeInvocationInterceptor#currentInvocation()引发异常而在正确的时间点被调用?

切入点有问题吗?我以此为参考:https://stackoverflow.com/a/38866088/361414

切入点是在带有这些注释的类中定义的:

@Aspect
@Component
@Order(20)

0 个答案:

没有答案