Spring源码-Aspect-内置Advisor与Interceptor 发表于: 2025-05-18 字数: 90 阅读:≈ 1分钟 总结摘要Spring AOP 内置Advisor与InterceptorExposeInvocationInterceptor 将 MethodInvocation 存储到 ThreadLocal 变量中。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public final class ExposeInvocationInterceptor implements MethodInterceptor, PriorityOrdered, Serializable { private static final ThreadLocal<MethodInvocation> invocation = new NamedThreadLocal<>("Current AOP method invocation"); public static MethodInvocation currentInvocation() throws IllegalStateException { MethodInvocation mi = invocation.get(); //... } @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { MethodInvocation oldInvocation = invocation.get(); invocation.set(mi); try { return mi.proceed(); } finally { invocation.set(oldInvocation); } } }END