0

I have the following classes

class A {
    public void someone() {
        helpMe();
    }
    private void helpMe() {
        // do something here
    }
}
class B extends A {
    public void help() {
        super.someone();
    }
}
class C extends A {
    public void me() {
        super.someone();
    }
}

So I want to do something everytime helpMe method is called. A.helpMe() is never called explicitly. All of the method calls for A.helpMe() is through A.someone() which is further called through either B.help() or C.me().

helpMe contains a common implementation that every other class needs.

pointcuts I have tried

execution(* A.helpMe(..)) // does not work
execution(* A+.helpMe(..)) // does not work
execution(* *.helpMe(..)) // does not work

execution(* A.*(..)) // does not work
execution(* B.someone(..)) // does not work
execution(* A+.*(..)) // forms a point cut for B.help() and C.me() only
execution(* *.*(..)) // forms a point cut for B.help() and C.me() only
execution(* B.*(..)) // forms a point cut for B.help() only

I read somewhere that pointcuts for super is not allowed. If thats the case, what are some valid work arounds?

I've tried getting pointcut with annotations but it does not work either.

Nischit Pradhan
  • 440
  • 6
  • 18
  • Spring AOP is applied through proxies, internal method calls cannot be intercepted. For this you would need a full blown AOP solution like AspectJ with either load or compile time weaving. – M. Deinum Nov 13 '19 at 12:19

1 Answers1

0

1 If in doubt, always fall back to to the fully hard-coded pointcut and work forward again:

execution(private void helpMe())

Are you sure you are using AspectJ and not vanilla Spring AOP (which cannot advise a private method)?


FYI: https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html

the call join point does not capture super calls to non-static methods

... which is not not applicable to execution.

drekbour
  • 2,895
  • 18
  • 28