Spring的事务管理是通过AOP代理实现的。 其中的事务通知由元数据(目前基于XML或注解)驱动。 代理对象与事务元数据结合产生了一个AOP代理,它使用一个PlatformTransactionManager 实现配合TransactionInterceptor,在方法调用前后实施事务。
主要涉及:JpaTransactionManager 、 AbstractPlatformTransactionManager 、PlatformTransactionManager、TransactionInterceptor 、TransactionProxyFactoryBean
声明式事物处理大致可以分为以下几个部分:
1.读取和处理在IOC容器中配置的事物处理属性。TransactionAttributeSourceAdvisor 、 TransactionProxyFactoryBean
2.spring事物处理模块实现统一的事物处理过程。TransactionInfo 、 TransactionStatus
3.底层事物处理实现。JpaTransactionManager
开始事务:
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:356)
getConnection:97, ProxoolDataSource (org.logicalcobwebs.proxool)
结束事务:
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
closeConnection:148, DatasourceConnectionProviderImpl (org.hibernate.service.jdbc.connections.internal)
完整堆栈:
getConnection:97, ProxoolDataSource (org.logicalcobwebs.proxool)
getConnection:70, InjectedDataSourceConnectionProvider (org.hibernate.ejb.connection)
obtainConnection:292, AbstractSessionImpl$NonContextualJdbcConnectionAccess (org.hibernate.internal)
obtainConnection:214, LogicalConnectionImpl (org.hibernate.engine.jdbc.internal)
getConnection:157, LogicalConnectionImpl (org.hibernate.engine.jdbc.internal)
doBegin:67, JdbcTransaction (org.hibernate.engine.transaction.internal.jdbc)
begin:160, AbstractTransactionImpl (org.hibernate.engine.transaction.spi)
beginTransaction:1426, SessionImpl (org.hibernate.internal)
begin:59, TransactionImpl (org.hibernate.ejb)
beginTransaction:189, HibernateJpaDialect (org.springframework.orm.jpa.vendor)
doBegin:380, JpaTransactionManager (org.springframework.orm.jpa)
getTransaction:377, AbstractPlatformTransactionManager (org.springframework.transaction.support)
createTransactionIfNecessary:461, TransactionAspectSupport (org.springframework.transaction.interceptor)
invokeWithinTransaction:277, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:96, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:52, MethodBeforeAdviceInterceptor (org.springframework.aop.framework.adapter)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:92, ExposeInvocationInterceptor (org.springframework.aop.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:671, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
executFailNotify:-1, WSLiveOperateFileService$$EnhancerBySpringCGLIB$$fd0f90b7 (com.chinanetcenter.wcs.service)
wsliveCallBackUrl:171, WSLiveCmdControl (com.chinanetcenter.wcs.rest)
invoke:-1, WSLiveCmdControl$$FastClassBySpringCGLIB$$a5ae8c78 (com.chinanetcenter.wcs.rest)
invoke:204, MethodProxy (org.springframework.cglib.proxy)
invokeJoinpoint:736, CglibAopProxy$CglibMethodInvocation (org.springframework.aop.framework)
proceed:157, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:52, MethodBeforeAdviceInterceptor (org.springframework.aop.framework.adapter)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:92, ExposeInvocationInterceptor (org.springframework.aop.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:671, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
wsliveCallBackUrl:-1, WSLiveCmdControl$$EnhancerBySpringCGLIB$$7e22f5e3 (com.chinanetcenter.wcs.rest)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
doInvoke:205, InvocableHandlerMethod (org.springframework.web.method.support)
invokeForRequest:133, InvocableHandlerMethod (org.springframework.web.method.support)
invokeAndHandle:97, ServletInvocableHandlerMethod (org.springframework.web.servlet.mvc.method.annotation)
invokeHandlerMethod:827, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handleInternal:738, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handle:85, AbstractHandlerMethodAdapter (org.springframework.web.servlet.mvc.method)
doDispatch:967, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doPost:872, FrameworkServlet (org.springframework.web.servlet)
service:661, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:361, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:225, DomainFilter (com.chinanetcenter.wcs.interceptor)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:18, ResponseTimeFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:38, RequestHeadFilter (com.chinanetcenter.wcs.interceptor)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilterInternal:76, CharacterContentTypeFilter (com.chinanetcenter.wcs.interceptor)
doFilter:107, OncePerRequestFilter (org.springframework.web.filter)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:198, StandardWrapperValve (org.apache.catalina.core)
invoke:96, StandardContextValve (org.apache.catalina.core)
invoke:496, AuthenticatorBase (org.apache.catalina.authenticator)
invoke:140, StandardHostValve (org.apache.catalina.core)
invoke:81, ErrorReportValve (org.apache.catalina.valves)
invoke:650, AbstractAccessLogValve (org.apache.catalina.valves)
invoke:87, StandardEngineValve (org.apache.catalina.core)
service:342, CoyoteAdapter (org.apache.catalina.connector)
service:803, Http11Processor (org.apache.coyote.http11)
process:66, AbstractProcessorLight (org.apache.coyote)
process:790, AbstractProtocol$ConnectionHandler (org.apache.coyote)
doRun:1459, NioEndpoint$SocketProcessor (org.apache.tomcat.util.net)
run:49, SocketProcessorBase (org.apache.tomcat.util.net)
runWorker:1149, ThreadPoolExecutor (java.util.concurrent)
run:624, ThreadPoolExecutor$Worker (java.util.concurrent)
run:61, TaskThread$WrappingRunnable (org.apache.tomcat.util.threads)
run:748, Thread (java.lang)
结束事务完整堆栈
close:215, ProxyConnection (org.logicalcobwebs.proxool)
invoke:134, WrappedConnection (org.logicalcobwebs.proxool)
intercept:87, WrappedConnection (org.logicalcobwebs.proxool)
close:-1, Wrapper$$EnhancerByProxool$$d97b1301 ($java.sql)
closeConnection:148, DatasourceConnectionProviderImpl (org.hibernate.service.jdbc.connections.internal)
releaseConnection:297, AbstractSessionImpl$NonContextualJdbcConnectionAccess (org.hibernate.internal)
releaseConnection:241, LogicalConnectionImpl (org.hibernate.engine.jdbc.internal)
close:168, LogicalConnectionImpl (org.hibernate.engine.jdbc.internal)
close:177, JdbcCoordinatorImpl (org.hibernate.engine.jdbc.internal)
close:277, TransactionCoordinatorImpl (org.hibernate.engine.transaction.internal)
close:354, SessionImpl (org.hibernate.internal)
close:137, EntityManagerImpl (org.hibernate.ejb)
closeEntityManager:438, EntityManagerFactoryUtils (org.springframework.orm.jpa)
doCleanupAfterCompletion:602, JpaTransactionManager (org.springframework.orm.jpa)
cleanupAfterCompletion:1021, AbstractPlatformTransactionManager (org.springframework.transaction.support)
processCommit:815, AbstractPlatformTransactionManager (org.springframework.transaction.support)
commit:734, AbstractPlatformTransactionManager (org.springframework.transaction.support)
commitTransactionAfterReturning:518, TransactionAspectSupport (org.springframework.transaction.interceptor)
invokeWithinTransaction:292, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:96, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:52, MethodBeforeAdviceInterceptor (org.springframework.aop.framework.adapter)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:92, ExposeInvocationInterceptor (org.springframework.aop.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:671, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
executFailNotify:-1, WSLiveOperateFileService$$EnhancerBySpringCGLIB$$4eff776f (com.chinanetcenter.wcs.service)
wsliveCallBackUrl:171, WSLiveCmdControl (com.chinanetcenter.wcs.rest)
invoke:-1, WSLiveCmdControl$$FastClassBySpringCGLIB$$a5ae8c78 (com.chinanetcenter.wcs.rest)
invoke:204, MethodProxy (org.springframework.cglib.proxy)
invokeJoinpoint:736, CglibAopProxy$CglibMethodInvocation (org.springframework.aop.framework)
proceed:157, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:52, MethodBeforeAdviceInterceptor (org.springframework.aop.framework.adapter)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:92, ExposeInvocationInterceptor (org.springframework.aop.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:671, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
wsliveCallBackUrl:-1, WSLiveCmdControl$$EnhancerBySpringCGLIB$$e462052b (com.chinanetcenter.wcs.rest)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
doInvoke:205, InvocableHandlerMethod (org.springframework.web.method.support)
invokeForRequest:133, InvocableHandlerMethod (org.springframework.web.method.support)
invokeAndHandle:97, ServletInvocableHandlerMethod (org.springframework.web.servlet.mvc.method.annotation)
invokeHandlerMethod:827, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handleInternal:738, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handle:85, AbstractHandlerMethodAdapter (org.springframework.web.servlet.mvc.method)
doDispatch:967, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doPost:872, FrameworkServlet (org.springframework.web.servlet)
service:661, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:361, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:225, DomainFilter (com.chinanetcenter.wcs.interceptor)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:18, ResponseTimeFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:38, RequestHeadFilter (com.chinanetcenter.wcs.interceptor)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilterInternal:76, CharacterContentTypeFilter (com.chinanetcenter.wcs.interceptor)
doFilter:107, OncePerRequestFilter (org.springframework.web.filter)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:198, StandardWrapperValve (org.apache.catalina.core)
invoke:96, StandardContextValve (org.apache.catalina.core)
invoke:496, AuthenticatorBase (org.apache.catalina.authenticator)
invoke:140, StandardHostValve (org.apache.catalina.core)
invoke:81, ErrorReportValve (org.apache.catalina.valves)
invoke:650, AbstractAccessLogValve (org.apache.catalina.valves)
invoke:87, StandardEngineValve (org.apache.catalina.core)
service:342, CoyoteAdapter (org.apache.catalina.connector)
service:803, Http11Processor (org.apache.coyote.http11)
process:66, AbstractProcessorLight (org.apache.coyote)
process:790, AbstractProtocol$ConnectionHandler (org.apache.coyote)
doRun:1459, NioEndpoint$SocketProcessor (org.apache.tomcat.util.net)
run:49, SocketProcessorBase (org.apache.tomcat.util.net)
runWorker:1149, ThreadPoolExecutor (java.util.concurrent)
run:624, ThreadPoolExecutor$Worker (java.util.concurrent)
run:61, TaskThread$WrappingRunnable (org.apache.tomcat.util.threads)
run:748, Thread (java.lang)