AOP AspectJ 切入点 if() 抛出 ArrayIndexOutOfBoundsException:

AOP AspectJ Pointcut if() throwing ArrayIndexOutOfBoundsException:

我正在尝试编写一个方面,试图实现切入点的 if() 条件但接收到 ArrayIndexOutOfBoundsException。这是代码片段。

@Pointcut("call(* com.aop.Service.activate(..)) && args(iActivate,..) && if()")
    public static boolean saveActivate(Activate iActivate) {
        return true; //if false @before she not be invoked
    };

@Before("saveActivate(iActivate)")
    public void saveActivateBefore(JoinPoint ijoinPoint, ActivateInstallmentRequest iActivateInstallmentRequest) {
        System.out.println("Log from @before");    
}

这段代码给出了以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]: Initialization of bean failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

有人可以帮我解决我在这里遗漏的问题吗? PS:我也提到了AspectJ

在确认您使用 Spring AOP 后,答案确实是 if()call() 均不受支持,另请参阅 Spring 手册部分pointcut designators.

如果您想使用这些指示符,您需要激活 AspectJ via LTW (load-time weaving)

Spring AOP 的解决方法是在建议方法的开头简单地使用常规 if,如果没有使用 call() 的特定原因,请使用execution() 相反,这是大多数人想要的。我不打算在这里详细说明调用和执行连接点之间的区别,但是您可以例如咨询 my answer there 了解更多信息。


更新:您的代码片段中还有其他看起来有点奇怪的地方,但我解释的是目前最大的问题。