接口 MethodInterceptor

所有超级接口:
Advice, Interceptor
所有已知子接口:
IntroductionInterceptor
所有已知实现类:
AbstractMonitoringInterceptor, AbstractTraceInterceptor, AfterReturningAdviceInterceptor, AspectJAfterAdvice, AspectJAfterThrowingAdvice, AspectJAroundAdvice, AsyncExecutionInterceptor, ConcurrencyThrottleInterceptor, CustomizableTraceInterceptor, DebugInterceptor, DelegatePerTargetObjectIntroductionInterceptor, DelegatingIntroductionInterceptor, ExposeBeanNameAdvisors.ExposeBeanNameInterceptor, ExposeBeanNameAdvisors.ExposeBeanNameIntroduction, ExposeInvocationInterceptor, MethodBeforeAdviceInterceptor, PerformanceMonitorInterceptor, RuntimeMethodInterceptor, SimpleTraceInterceptor, ThrowsAdviceInterceptor
函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface public interface MethodInterceptor extends Interceptor
Intercepts calls on an interface on its way to the target. These are nested "on top" of the target.

The user should implement the invoke(MethodInvocation) method to modify the original behavior. E.g. the following class implements a tracing interceptor (traces all the calls on the intercepted method(s)):

 class TracingInterceptor implements MethodInterceptor {
     Object invoke(MethodInvocation i) throws Throwable {
         System.out.println("method " + i.getMethod() + " is called on " + i.getThis() + " with args " + i.getArguments());
         Object ret = i.proceed();
         System.out.println("method " + i.getMethod() + " returns " + ret);
         return ret;
     }
 }
 
  • 方法概要

    修饰符和类型
    方法
    说明
    Implement this method to perform extra treatments before and after the invocation.
  • 方法详细资料

    • invoke

      @Nullable Object invoke(MethodInvocation invocation) throws Throwable
      Implement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invoke Joinpoint.proceed().
      参数:
      invocation - the method invocation joinpoint
      返回:
      the result of the call to Joinpoint.proceed(), might be intercepted by the interceptor.
      抛出:
      Throwable - if the interceptors or the target-object throws an exception.