Home » Java » java – AspectJ not working for class that implements AsyncUncaughtExceptionHandler-Exceptionshub

java – AspectJ not working for class that implements AsyncUncaughtExceptionHandler-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have the following class:

@Component
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

    @Override
    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
        System.out.println("Error handling!"); 
    }
}

And I have the following aspect:

@Before("execution(* org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler.handleUncaughtException(java.lang.Throwable, java.lang.reflect.Method, java.lang.Object...)) && "
        + "args(ex, method, params) && target(myapplication.exception.handler.AsyncExceptionHandler)")
public void asyncExceptionHandlerHandleUncaughtExceptionBefore(Throwable ex, Method method, Object... params) {
    System.out.println("Aspect OK!"); 
}

I need this aspect due to a standard way to log in to my application.
Today, this class of aspects has a lot of aspects that are working!
Only this aspect is not working!

Question:

  1. I guess is not possible to intercept the AsyncUncaughtExceptionHandler implementation (an
    interceptor). Is that?
  2. Something related to varags params?
How to&Answers: