23.Spring事務(wù)注解@Transactional和異常捕獲-創(chuàng)新互聯(lián)

一. 事務(wù)注解限制條件

創(chuàng)新互聯(lián)成立以來不斷整合自身及行業(yè)資源、不斷突破觀念以使企業(yè)策略得到完善和成熟,建立了一套“以技術(shù)為基點(diǎn),以客戶需求中心、市場為導(dǎo)向”的快速反應(yīng)體系。對公司的主營項(xiàng)目,如中高端企業(yè)網(wǎng)站企劃 / 設(shè)計(jì)、行業(yè) / 企業(yè)門戶設(shè)計(jì)推廣、行業(yè)門戶平臺運(yùn)營、app軟件定制開發(fā)成都做手機(jī)網(wǎng)站、微信網(wǎng)站制作、軟件開發(fā)、德陽服務(wù)器托管等實(shí)行標(biāo)準(zhǔn)化操作,讓客戶可以直觀的預(yù)知到從創(chuàng)新互聯(lián)可以獲得的服務(wù)效果。

1. 不允許在private方法上面

2. 不能在非事務(wù)方法里面調(diào)用事務(wù)方法

二. 實(shí)現(xiàn)機(jī)制-異常捕獲

Describes transaction attributes on a method or class.
This annotation type is generally directly comparable to Spring's org.springframework.transaction.interceptor.RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction 
support code does not have to know about annotations. If no rules are relevant 
to the exception, it will be treated like org.springframework.transaction.interceptor.DefaultTransactionAttribute (rolling back on RuntimeException and Error but not on checked exceptions).
For specific information about the semantics of this annotation's attributes, 
consult the org.springframework.transaction.TransactionDefinition and org.springframework.transaction.interceptor.TransactionAttribute javadocs.

所以如果操作數(shù)據(jù)庫的時(shí)候把異常捕獲了,那么將不能回滾。

三. 手動回滾

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

所以為了解決這種矛盾,可以捕獲異常后,在catch里面手動調(diào)用回滾。


創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。

分享題目:23.Spring事務(wù)注解@Transactional和異常捕獲-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://muchs.cn/article32/dpgcpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、Google、App設(shè)計(jì)、商城網(wǎng)站電子商務(wù)、小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)