5

i have two aspects, one for acquiring a lock @Around a call, another one for debouncing method calls. the aspects look like this:

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

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

and the other one looks like this:

@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

}

the full code:

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

and

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

when i put both my @Debounce and my @Lock on a method, i get this exception:

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)

it seems to be related to spring aop not being able to figure out the next thing to call in line is another aspect, not the actual target, and i have seen other reports from spring aop 2 and 3 ... but i am using:

spring 4.1.1.RELEASE
rmalchow
  • 2,689
  • 18
  • 31
  • Isn't the convention to use `pjp.proceed()` unless you actually need to manipulate the parameters to the method? You're using `pjp.proceed(pjp.getArgs())` in `LockAspect` – beerbajay May 08 '15 at 09:00
  • yes. i tried it both ways. same exception. – rmalchow May 08 '15 at 09:43

1 Answers1

0

sorry for my poor English. did you ordered the Aspect Class? if you didn't,this problem may happend

you could try this for example:

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

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

the value is lower ,the priority is higher

runbird
  • 81
  • 1
  • 1
  • 4