Java transaction (8)-distributed transaction-spring + JTA + atomikos
I. Preface:
In the previous blog, we used jotm to implement distributed transactions. This article uses atomikos.
The basic code is the same, that is, the configuration is slightly different.
Ii. Code implementation:
1. code structure:
2. configuration file: ApplicationContext. xml
Mysql/main
Com. mysql. jdbc. jdbc2.optional. MysqlXADataSource
URL = jdbc: mysql: // localhost: 3306/user? UseUnicode = true & characterEncoding = UTF-8; user = root; password = root
True
3
SELECT 1
Mysql/secondary
Com. mysql. jdbc. jdbc2.optional. MysqlXADataSource
URL = jdbc: mysql: // localhost: 3306/log? UseUnicode = true & characterEncoding = UTF-8; user = root; password = root
True
3
SELECT 1
For other code, see the previous blog.
Source code download: http://download.csdn.net/detail/zdp072/7950391