簡體   English   中英

在春季聲明式事務管理中,提交事務時

[英]In spring declarative transaction management when transaction commited

如所描述的,春季聲明式交易管理中實際執行的交易。 例如,假設我有以下代碼

@Service
@Transactional
class CustomerAService{
    public void processCustomer(Customer customer){
        //call dao and insert customer
        furtherProcessCustomer(Customer customer);
        //last line (a)
    }

    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void furtherProcessCustomer(Customer customer){
        //call another dao do some db work

        //last line (b)
    }
}

假設如果我停止執行@行//最后一行(a),那么會為processCustomer()方法提交事務。 我試圖在網上搜索,但沒有得到太多信息

春天的事務管理是通過面向方面的編程(AOP)代理對象進行的。 這意味着該方法必須干凈地返回以便提交事務。 下圖中的代碼是“目標方法”,而事務是在“事務顧問”中提交的。 此處有更多文檔。

AOP交易處理

您的示例有點微妙,因為在同一類內部調用了furtherProcessCustomer方法,該方法不會通過AOP代理對象進行調用,因此不會使用@Transactional(propagation=Propagation.REQUIRES_NEW)

如果您還有另一個服務(也帶有@Transactional批注),然后又調用了furtherProcessCustomer ,則這將通過AOP代理對象發生,因此將具有嵌套事務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM