gpt4 book ai didi

java - spring aop - 链接多个方面

转载 作者:搜寻专家 更新时间:2023-11-01 03:50:23 28 4
gpt4 key购买 nike

我有两个方面,一个用于获取锁定 @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 not being able to figure out the next thing to call in line有关是另一个方面,而不是实际目标,我已经看到了spring aop 2和3的其他报告......但我正在使用:

spring 4.1.1.RELEASE

最佳答案

对不起我的英语不好。您订购了 Aspect Class 吗?如果你不这样做,这个问题可能会发生

你可以试试这个,例如:

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

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

值越小,优先级越高

关于java - spring aop - 链接多个方面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30118862/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com