原創 spring 多資料庫(資料來源) jta 事務2 收藏
注:本文引自
最近乙個專案要跨多資料,配多資料來源的,其中就用到了事務,毫無疑問我選擇的是spring的宣告式jta事務。我的環境是jboss+oracle 9i
自己私下做了些實驗,不過還是成功了
實驗一:mysql 5.0
採用atomikos的jta事務(要感謝
view plaincopy to clipboardprint?
1. <?xml version=」1.0″ encoding=」utf-8″?>
2.
8. 9.
11.
12. mysql/main
13.
14.
15. =5.0, connector/j>=5.0才可以支援xadatasource)–>
16. com.mysql.jdbc.jdbc2.optional.mysqlxadatasource
17.
18.
19. url=jdbc:mysql://localhost:3306/crm?useunicode=true&characterencoding=utf-8;user=root;password=root
20.
21.
22. true
23.
24.
25. 3
26.
27.
28. select 1
29.
30.
31.
32.
34.
35. mysql/news
36.
37.
38. =5.0, connector/j>=5.0才可以支援xadatasource)
40. –>
41. com.mysql.jdbc.jdbc2.optional.mysqlxadatasource
42.
43.
44. url=jdbc:mysql://localhost:3306/crm2?useunicode=true&characterencoding=utf-8;user=root;password=root
45.
46.
47. true
48.
49.
50. 3
51.
52.
53. select 1
54.
55.
56.
57.
58.
59.
60.
61.
62.
63. classpath:sqlmapconfig.xml
64.
65.
66.
67.
68.
69.
70.
71.
72. classpath:sqlmapconfig2.xml
73.
74.
75.
76.
77.
78.
79.
81.
82.
85.
86.
87.
88. com.atomikos.icatch.standalone.usertransactionservicefactory
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
102.
103.
104.
105.
106.
109.
110.
111.
112.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
<?xml version=」1.0″ encoding=」utf-8″?> mysql/main
=5.0, connector/j>=5.0才可以支援xadatasource)–> com.mysql.jdbc.jdbc2.optional.mysqlxadatasource
url=jdbc:mysql://localhost:3306/crm?useunicode=true&characterencoding=utf-8;user=root;password=root
true
3 select 1
mysql/news
=5.0, connector/j>=5.0才可以支援xadatasource) –> com.mysql.jdbc.jdbc2.optional.mysqlxadatasource
url=jdbc:mysql://localhost:3306/crm2?useunicode=true&characterencoding=utf-8;user=root;password=root
true
3 select 1
classpath:sqlmapconfig.xml
classpath:sqlmapconfig2.xml
com.atomikos.icatch.standalone.usertransactionservicefactory
這樣是成功的 可是切換oracle9i時悲劇發生了
— cause: com.atomikos.datasource.resourceexception: resume for xid oracle.jdbc.xa.oraclexid@145f939 raised -3: the xa resource detected an internal error
caused by: com.ibatis.common.jdbc.exception.nestedsqlexception:
— the error occurred in ibatis/product1.xml.
— the error occurred while executing update.
官方說oracle連線問題 哎。。。無語了
換了一種jta事務機制 通過jotm
view plaincopy to clipboardprint?
1. <?xml version=」1.0″ encoding=」utf-8″?>
2.
8. 9.
10.
11.
12.
13.
14.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46. classpath:sqlmapconfig_ora1.xml
47.
48.
49.
50.
51.
52.
53.
54. classpath:sqlmapconfig_ora2.xml
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
<?xml version=」1.0″ encoding=」utf-8″?>
classpath:sqlmapconfig_ora1.xml
classpath:sqlmapconfig_ora2.xml
成功了。。。
很好很好 哈哈哈
舊一篇:spring 多資料來源 jta 事務 | 新一篇:禁止頁面的選擇和複製功能
spring 多資料來源
之前嘗試的乙個多資料來源切換的功能測試可以實現了,下面進行一下簡單的筆記 testservice 方法通過以下方式進行主動切換 dynamicdatasource 類 package com.utils import org.springframework.jdbc.datasource.looku...
SpringBoot 資料庫多資料來源
兩個專案間資料同步的需求,需要同時操作多個庫多需求 component中建立不同的檔案 datasourcedefault configuration basepackages sqlsessionfactoryref sqlsessionfactory2 public class datasour...
spring多資料來源配置
前段時間由於公司專案需求,需要多資料來源的支援,苦b折騰了兩天程式猿,話不多說,直接擼碼。classpath jdbc.properties select 1 true select 1 true org.hibernate.dialect.mysqldialect false update tru...