Search code examples
springaspectjspring-aoppointcut

spring aspectj pointcut reusable class


as described in https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-common-pointcuts

Is it possible to create an independent class defining all the pointcuts and use it in other aspects, so that we should be able to reuse the pointcuts?

If I use the pointcut from that class, I get an error:

Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inServiceLayer
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)

But if I include the method in the existing aspect, it works fine.

Thanks,


Solution

  • It was all my fault, I hadn't defined the fully qualified method name including package and class name.