?
spring調用一個方法后的事務處理過程:
請
參照TransactionInterceptor的invoke方法:
?1
try
?
{
?2
???
//
?This?is?an?around?advice.
?3
???
//
?Invoke?the?next?interceptor?in?the?chain.
?4
???
//
?This?will?normally?result?in?a?target?object?being?invoked.
?5
???retVal?
=
?invocation.proceed();
?6
??}
?7
??
catch
?(Throwable?ex)?
{
?8
???
//
?target?invocation?exception
?9
???doCloseTransactionAfterThrowing(txInfo,?ex);
10
???
throw
?ex;
11
??}
12
??
finally
?
{
13
???doFinally(txInfo);
14
??}
15
??doCommitTransactionAfterReturning(txInfo);
16
??
return
?retVal;
17
?}



?2

?3

?4

?5

?6

?7



?8

?9

10

11

12



13

14

15

16

17

?
調用目標方法時沒有拋出異常時會調用:
doCommitTransactionAfterReturning(txInfo);
然后直接提交事務
?
如果拋異常則檢查是否需要回滾事務(doCloseTransactionAfterThrowing方法會根據在spring中設備的Transaction Attribute),否則提交事務.
參考資料:
1.Spring Reference Manual:http://static.springframework.org/spring/docs/1.2.x/reference/index.html
2.Spring API doc:http://static.springframework.org/spring/docs/1.2.x/api/index.html
3.Spring 的源代碼
作者簡介:
????施祖陽,網名sylilzy,1979年生。
????2002年起從事軟件開發工作,主要研究為JAVA、Linux及相關技術。
????你可通過
sylilzy@163.com
與作者聯系。