新版分布式事務框框有阿里的Seata,可前往自行研究,我暫時沒有使用過:https://github.com/seata/seata或https://gitee.com/seata-io/seata
1.pom依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jta-atomikos</artifactId> </dependency>
2.application.properties配置文件
3. Atomikos的原理
A. 每個數據源執行時獲取一個標記事務的唯一ID;
B. 每個數據源做execute;
C. 每個數據源做end,標記這個數據庫的sql已經執行完畢,不會再執行別的語句,該事務已經可以提交了;
D. 每個數據源做prepare,預提交該事務;
E. 如果所有的prepare都是成功的,則commit,否則rollback。
10.JTA分布式事務執行報org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: Prepare: NO vote atomikos版本3.9.3
解決方式:在application.properties文件中
# 默認的超時時間單位毫秒
spring.jta.atomikos.properties.default-jta-timeout=30000000
spring.jta.atomikos.properties.max-timeout=3000000
#配置最大的事務活動個數,-1代表無限制(atomikos版本3.9.3)
spring.jta.atomikos.properties.max-actives=-1
可參考:https://blog.csdn.net/u011042955/article/details/86998664
可參考:http://blog.jobbole.com/95632/
https://sylvanassun.github.io/2016/08/01/2016-08-1-Spring-data-transaction/
https://blog.csdn.net/cckevincyh/article/details/79189888
