spring 事物处理机制

ReflectiveMethodInvocation.proceed()
调用过程:

ReflectiveMethodInvocation 中的((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this)
会有一个拦截器去一调用,this关键字会回调
//都会回调ReflectiveMethodInvocation.proceed()
1 ExposeInvocationInterceptor–>invoke()
2 TransactionInterceptor–>invoke()–>invokeWithinTransaction(callBack)
3ReflectiveMethodInvocation.invokeJoinpoint()
4 AopUtils.invokeJoinpointUsingReflection()

首先需要运行在实物上下文环境,service的调用都是动态代理,例子中的是jdk动态代理,然后进过一系列的拦截器, 调用proceed() 最后调用
invokeJoinpoint() 最后执行目标类的方法
调用关系:

Daemon Thread [http-bio-8080-exec-2] (Suspended)
TransactionInterceptor 1.proceedWithInvocation()line:96TransactionInterceptor(TransactionAspectSupport).invokeWithinTransaction(Method,Class,TransactionAspectSupport InvocationCallback) line: 260
TransactionInterceptor.invoke(MethodInvocation) line: 94
ReflectiveMethodInvocation.proceed() line: 172
ExposeInvocationInterceptor.invoke(MethodInvocation) line: 91
ReflectiveMethodInvocation.proceed() line: 172
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 204
Proxy194.save()line:notavailableTestController.list(HttpServletRequest)line:151NativeMethodAccessorImpl.invoke0(Method,Object,Object[])line:notavailable[nativemethod]NativeMethodAccessorImpl.invoke(Object,Object[])line:57DelegatingMethodAccessorImpl.invoke(Object,Object[])line:43Method.invoke(Object,Object)line:601AnnotationMethodHandlerAdapter ServletHandlerMethodInvoker(HandlerMethodInvoker).invokeHandlerMethod(Method, Object, NativeWebRequest, ExtendedModelMap) line: 176
AnnotationMethodHandlerAdapter.invokeHandlerMethod(HttpServletRequest, HttpServletResponse, Object) line: 440
AnnotationMethodHandlerAdapter.handle(HttpServletRequest, HttpServletResponse, Object) line: 428

TransactionInterceptor$1.proceedWithInvocation() line: 96

TransactionInterceptor(TransactionAspectSupport).invokeWithinTransaction(
Method, Class, TransactionAspectSupport$InvocationCallback) line: 260

TransactionInterceptor.invoke(MethodInvocation) line: 94

ReflectiveMethodInvocation.proceed() line: 172

ExposeInvocationInterceptor.invoke(MethodInvocation) line: 91

ReflectiveMethodInvocation.proceed() line: 172

JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 204

$Proxy194.save() line: not available
TestController.list(HttpServletRequest) line: 151

NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]

NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57

DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object…) line: 601

AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker(HandlerMethodInvoker).invokeHandlerMethod(Method, Object, NativeWebRequest, ExtendedModelMap) line: 176

AnnotationMethodHandlerAdapter.invokeHandlerMethod(HttpServletRequest,
HttpServletResponse, Object) line: 440

AnnotationMethodHandlerAdapter.handle(HttpServletRequest, HttpServletResponse, Object) line: 428

DispatcherServlet.doDispatch(HttpServletRequest, HttpServletResponse) line: 925
— 待续

service 都被动态代理了
每次访问的时候都会调用
JdkDynamicAopProxy.invoke() 方法

你可能感兴趣的:(java,心得)