spring mybatis atomikos 多庫分散式事務demo
阿新 • • 發佈:2019-01-19
最近有點時間 , 就準備搭個多庫事務的例子 , 不過中間碰到一些問題 , 這裡記錄下來 .
我的atomikos 版本是 3.7.0 ; Spring4 mybatis3 ;
碰到問題主要有兩類 :
1 : 缺少依賴jar包
atomikos-util.jar
transactions.jar
transactions-jta.jar
transactions-jdbc-deprecated.jar
mybatis.jar
mybatis-spring.jar
cglib.2.2.2.jar
jta.jar
2 : 配置檔案編寫錯誤
開始網上down了個配置 , 如下 :
<
bean
id
=
"dataSource"
class
=
"com.atomikos.jdbc.SimpleDataSourceBean"
init-method
=
"init"
destroy-method
=
"close"
>
<
property
name
=
"uniqueResourceName"
value
=
"mysql/main"
/>
<
property
name
=
"xaDataSourceClassName"
value
=
"com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"
/>
<
property
name
=
"xaDataSourceProperties"
value
=
"URL=${jdbc.url.a};user=${jdbc.username.a};password=${jdbc.password.a}"
/>
<
property
name
=
"exclusiveConnectionMode"
value
=
"true"
/>
<
property
name
=
"connectionPoolSize"
value
=
"10"
/>
<
property
name
=
"validatingQuery"
>
<
value
>SELECT
1</
value
>
</
property
>
</
bean
>
額 ... 這個跑起來是報錯的 .........
ds應該醬紫寫 :
<beanname="dataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<propertyname="uniqueResourceName">
<value>ds1</value>
</property>
<propertyname="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<propertyname="xaProperties">
<props>
<propkey="URL">${ds1.jdbc.url}</prop>
<propkey="user">${ds1.jdbc.username}</prop>
<propkey="password">${ds1.jdbc.password}</prop>
</props>
</property>
<propertyname="poolSize"><value>1</value></property>
<propertyname="maxPoolSize"><value>30</value></property>
</bean>
<beanname="dataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<propertyname="uniqueResourceName">
<value>ds2</value>
</property>
<propertyname="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<propertyname="xaProperties">
<props>
<propkey="URL">${ds2.jdbc.url}</prop>
<propkey="user">${ds2.jdbc.username}</prop>
<propkey="password">${ds2.jdbc.password}</prop>
</props>
</property>
<propertyname="poolSize"><value>1</value></property>
<propertyname="maxPoolSize"><value>30</value></property>
</