简体   繁体   中英

Spring AOP java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

I want to create aspect which would intercept all methods annotatated with MyAnnotation and having parameter type of MyAbstractObject (different classes extends it and those methods having classes that extend it also should be intercepted)

@Before("@annotation(mypackage.MyAnnotation) && args(mypackage.MyAbstractObject ,..)")
public void doSomething(MyAbstractObject myObject) 

Sample methods:

@MyAnnotation
public void toBeIntercepted(MyObjectExtendingMyAbstractObject x)

It was working with annotation only. But I had to extract parameters from jointpoint which was ugly. Now I am changing it.

This generates the following exception:

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319) ~[aspectjweaver-1.9.4.jar:na]
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:227) ~[spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:198) ~[spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:177) ~[spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:225) ~[spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]```

The args() format is incorrect.

The correct format for that pointcut expression is as follows

@Before("@annotation(mypackage.MyAnnotation) && args(myObject,..)")
public void doSomething(MyAbstractObject myObject) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM