spring aop - 链接多个方面

时间:2015-05-08 08:05:52

标签: java spring aop spring-aop spring-aspects

我有两个方面,一个用于获取锁定@Around一个呼叫,另一个用于去除方法调用。方面看起来像这样:

@Pointcut("execution(public * * (..))")  
private void anyPublicMethod() {}

@Around("anyPublicMethod() && @annotation(lock)")
public Object all(ProceedingJoinPoint proceedingJoinPoint, Lock lock) throws Throwable {
   // acquire lock, then proceed()
}

另一个看起来像这样:

@Pointcut("execution(public * * (..))")  
private void anyPublicMethod() {}

@Around("anyPublicMethod() && @annotation(debounce)")
public Object all(ProceedingJoinPoint proceedingJoinPoint, Debounce debounce) throws Throwable {
    // debouncing as described in 
    // http://stackoverflow.com/questions/4742210/implementing-debounce-in-java

}

完整代码:

https://github.com/rmalchow/debouncer-aspect/blob/master/src/main/java/com/skjlls/aspects/debounce/impl/DebounceAspect.java

https://github.com/rmalchow/lock-aspect/blob/master/src/main/java/com/skjlls/aspects/lock/impl/LockAspect.java

当我将@Debounce和@Lock放在一个方法上时,我得到了这个例外:

Required to bind 2 arguments, but only bound 1 (JoinPointMatch was NOT bound in invocation)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.argBinding(AbstractAspectJAdvice.java:584)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)

它似乎与spring aop有关无法弄清楚下一个要排队的事情是另一个方面,而不是实际的目标,而且我已经看到了来自Spring aop 2和3的其他报告...但是我我正在使用:

spring 4.1.1.RELEASE

1 个答案:

答案 0 :(得分:0)

对不起,我英语不好。 您是否订购了方面类?如果没有,可能会发生此问题

您可以尝试以下操作:

@Aspect
@Order(1)
public class FirstAspect(){}

@Aspect
@Order(2)
public class SecondAspect(){}

值越低,优先级越高