0

example:

@Component
public class ExecutionClass extends ExtensionClass{
    public void doSomething(@MyAnnotation String hello){
        doSuperTask(hello);
    }
}

public class ExtensionClass{
    public void doSuperTask(@AnotherAnnotation String hello){
        doAnotherTask(hello);
    }

    public void doAnotherTask(@YetAnotherAnnotation String hello){
        //do some stuff
    }
}


@Override
@Around("execution(public * com.test..*(..))")
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    //invoke whatever around method
}

However, this results in only ExecutionClass#doSomething AOP to be in effect, while the rest are ignored. How to fix and make the interceptor intercept every public method?

All have the package of com.test.**

theAnonymous
  • 1,701
  • 2
  • 28
  • 62
  • Spring uses proxies, if you do method calls inside the proxy those won't be interested. A drawback of proxy based AOP. – M. Deinum Jun 30 '21 at 14:40
  • any way to workaround this and make it trigger? other than autowiring a new class and putting the logic in that new class. – theAnonymous Jun 30 '21 at 15:32
  • 1
    @theAnonymous self reference is a way to do this. Within `ExecutionClass` one can autowire a self reference like `@Autowired ExecutionClass self`. Now a call from `doSomething()` like `self.doSuperTask(hello);` will go through the proxy and gets intercepted – R.G Jul 01 '21 at 02:57
  • Either self invocation or by using full blown AspectJ with either load or compile time weaving. – M. Deinum Jul 01 '21 at 05:03

0 Answers0