2

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,

krmanish007
  • 6,749
  • 16
  • 58
  • 100
  • See the link below, your problem will probably be solved https://jstobigdata.com/spring/combine-and-reuse-pointcut-expressions-in-spring-aop/ – fatemeakbari Oct 20 '22 at 13:41

2 Answers2

0

That's what the example is showing.

There is the SystemArchitecture class that is defining many pointcuts and other class BeforeExample, AfterReturningExample, ... that are defining the advices, referencing the SystemArchitecture pointcuts in their annotation.

All of these classes are annotated with @Aspect.

Matthieu Saleta
  • 1,388
  • 1
  • 11
  • 17
0

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

krmanish007
  • 6,749
  • 16
  • 58
  • 100
  • That is the problem with sharing insufficient information when asking a question: You have to find the solution by yourself because nobody else can help you. So next time please share an [SSCCE](http://sscce.org/) so as to make the problem reproduceable. Only a stacktrace without source code and configuration is just as useless as the other way around. ;-) P.S.: You can accept your own answer so as to close the question, it is still listed as open. – kriegaex Feb 16 '17 at 13:47