Pointcut expression 'if()' contains unsupported pointcut primitive 'if'

可紊 提交于 2019-12-11 15:27:49

问题


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

I have declared a if() point cut:

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;
    }
}

At compile time, I get error:

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

My declared dependencies:

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

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


回答1:


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 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.



来源:https://stackoverflow.com/questions/57418907/pointcut-expression-if-contains-unsupported-pointcut-primitive-if

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!