切入点表达式'if()'包含不受支持的切入点基元'if' [英] Pointcut expression 'if()' contains unsupported pointcut primitive 'if'

查看:143
本文介绍了切入点表达式'if()'包含不受支持的切入点基元'if'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在AOP的Spring启动项目中使用AspectJ.

I am using AspectJ in my Spring boot project for AOP.

我已声明 if()切入点:

public class myPointCuts {
   // a global boolean variable, value can be updated at runtime.
   public static boolean IS_RESULT_FINE;

   @Pointcut("if()")
    public static boolean isResultFine() {
            return IS_RESULT_FINE;
    }
}

在编译时出现错误:

Initialization of bean failed;
nested exception is org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException: Pointcut expression 'if()' contains unsupported pointcut primitive 'if'

我声明的依赖项:

implementation 'org.springframework:spring-aop:5.0.1.RELEASE'
implementation 'org.aspectj:aspectjweaver:1.9.4'

我的if()切点表达式有什么问题?

What is wrong with my if() point cut expression ?

推荐答案

可能您正在尝试在Spring AOP中使用if(),但是作为错误消息不支持的切入点原语'if'" 暗示if()在Spring AOP中不可用,仅在AspectJ中不可用,这也在相应的

Probably you are trying to use if() in Spring AOP, but as the error message "unsupported pointcut primitive 'if'" implies, if() is not available in Spring AOP, only in AspectJ, which is also explained in the corresponding Spring manual section. You find a positive and negative list there.

如果要使用if(),则确实需要切换到

If you want to use if() you do need to switch to AspectJ with load-time weaving. But I am not sure it is worth switching the AOP framework for the sake of the if() pointcut which is not much more than syntactic sugar for an if (IS_RESULT_FINE) statement you could also just put right into your advice method.

这篇关于切入点表达式'if()'包含不受支持的切入点基元'if'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆