- 浏览: 269441 次
- 性别:
- 来自: 新乡
文章分类
- 全部博客 (227)
- servciemix (10)
- db (18)
- javaTools (4)
- hibernate (31)
- web (3)
- spring (14)
- design pattern (4)
- java security (3)
- portal (1)
- ejb (6)
- session (2)
- java_lang (21)
- jbpm (29)
- struts (7)
- orgRights (2)
- project manager Jira (7)
- 跨库事务 (2)
- mysql (14)
- ubuntu (7)
- osgi (9)
- maven ant make (4)
- 分布式 高并发 高性能 (5)
- virgo-dm_server (0)
- osgi web (3)
- platform (1)
- smooks (1)
- business (1)
- 职场生涯 (14)
- Java编码格式 (2)
- web服务 (1)
- 计算机使用 (1)
- 健康工作生活的保障,工作中务必抛掉的不良心态 (4)
- 电信-网络监控 (1)
- 多线程-multithread (1)
- 海量数据-高性能 (2)
- Mybatis (1)
- web开发平台研发 (0)
- oracle (0)
- 应用服务器调优 (0)
- web前端 (0)
- servlet-jsp (0)
- tomcat (2)
- newtouch (1)
- portal_liferay (2)
- version control (1)
- apm-impact (2)
- tools (1)
- 研发管理 (1)
- 电商业务 (1)
- 生鲜电商市场调查 (0)
- PBX (0)
- 房东 (0)
最新评论
-
lifuchao:
...
权限问题 -
Branding:
谢谢,受教了,另外,CONN AS SYSDBA,必须是在操作 ...
Oracle密码忘记了怎么办? -
zhuchao_ko:
...
Portal实现原理 -
败类斯文:
不知道改哪里。。。木有见到红色。。表示悟性低了、、
jira error: Neither the JAVA_HOME nor the JRE_HOME environment variable is defin -
c__06:
正文:假如事务我是这样定义的: <tx:method n ...
Spring中Transactional配置
原创 spring 多数据库(数据源) JTA 事务2 收藏
注:本文引自http://malaqu.com/?p=542
最近一个项目要跨多数据,配多数据源的,其中就用到了事务,毫无疑问我选择的是Spring的声明式JTA事务。我的环境是JBOSS+ORACLE 9I
自己私下做了些实验,不过还是成功了
实验一:MySQL 5.0
采用atomikos的jta事务(要感谢 http://andyao.iteye.com/)
view plaincopy to clipboardprint?
1. <?xml version=”1.0″ encoding=”UTF-8″?>
2. <beans xmlns=”http://www.springframework.org/schema/beans”
3. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop”
4. xmlns:tx=”http://www.springframework.org/schema/tx”
5. xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”>
8.
9. <bean id=”dataSource” class=”com.atomikos.jdbc.SimpleDataSourceBean”
10. init-method=”init” destroy-method=”close”>
11. <property name=”uniqueResourceName”>
12. <value>mysql/main</value>
13. </property>
14. <property name=”xaDataSourceClassName”>
15. <!–使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)–>
16. <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
17. </property>
18. <property name=”xaDataSourceProperties”>
19. <value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value>
20. </property>
21. <property name=”exclusiveConnectionMode”>
22. <value>true</value>
23. </property>
24. <property name=”connectionPoolSize”>
25. <value>3</value>
26. </property>
27. <property name=”validatingQuery”>
28. <value>SELECT 1</value>
29. </property>
30. </bean>
31. <!– 第二个数据库 –>
32. <bean id=”dataSourceB” class=”com.atomikos.jdbc.SimpleDataSourceBean”
33. init-method=”init” destroy-method=”close”>
34. <property name=”uniqueResourceName”>
35. <value>mysql/news</value>
36. </property>
37. <property name=”xaDataSourceClassName”>
38. <!–
39. 使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)
40. –>
41. <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
42. </property>
43. <property name=”xaDataSourceProperties”>
44. <value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value>
45. </property>
46. <property name=”exclusiveConnectionMode”>
47. <value>true</value>
48. </property>
49. <property name=”connectionPoolSize”>
50. <value>3</value>
51. </property>
52. <property name=”validatingQuery”>
53. <value>SELECT 1</value>
54. </property>
55. </bean>
56.
57. <bean id=”lobHandler” class=”org.springframework.jdbc.support.lob.DefaultLobHandler” />
58.
59. <!– 第一个数据库的sqlMapClient –>
60. <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
61. <property name=”configLocation”>
62. <!– 包含第一个数据库表的map –>
63. <value>classpath:SqlMapConfig.xml</value>
64. </property>
65. <property name=”dataSource” ref=”dataSource” />
66. <property name=”lobHandler” ref=”lobHandler” />
67. </bean>
68. <!– 第二个数据库的sqlMapClient –>
69. <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
70. <property name=”configLocation”>
71. <!– 包含第一个数据库表的map –>
72. <value>classpath:SqlMapConfig2.xml</value>
73. </property>
74. <property name=”dataSource” ref=”dataSourceB” />
75. <property name=”lobHandler” ref=”lobHandler” />
76. </bean>
77.
78. <!– Optional: add a log administrator –>
79. <bean id=”localLogAdministrator”
80. class=”com.atomikos.icatch.admin.imp.LocalLogAdministrator”/>
81.
82. <bean id=”userTransactionService”
83. class=”com.atomikos.icatch.config.UserTransactionServiceImp”
84. init-method=”init” destroy-method=”shutdownForce”>
85. <constructor-arg>
86. <!– IMPORTANT: specify all Atomikos properties here –>
87. <props>
88. <prop key=”com.atomikos.icatch.service”>com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
89. </props>
90. </constructor-arg>
91. <property name=”initialLogAdministrators”>
92. <list>
93. <ref bean=”localLogAdministrator”/>
94. </list>
95. </property>
96. </bean>
97. <!–Construct Atomikos UserTransactionManager,needed to configure Spring –>
98. <bean id=”AtomikosTransactionManager”
99. class=”com.atomikos.icatch.jta.UserTransactionManager”
100. init-method=”init” destroy-method=”close”
101. depends-on=”userTransactionService”>
102. <!–when close is called,should we force transactions to terminate or not?–>
103. <property name=”forceShutdown” value=”false” />
104. </bean>
105. <!–Also use Atomikos UserTransactionImp, needed to configure Spring–>
106. <bean id=”AtomikosUserTransaction”
107. class=”com.atomikos.icatch.jta.UserTransactionImp”
108. depends-on=”userTransactionService”>
109. <property name=”transactionTimeout” value=”300″ />
110. </bean>
111. <!– Configure the Spring framework to use JTA transactions from Atomikos –>
112. <bean id=”JtaTransactionManager”
113. class=”org.springframework.transaction.jta.JtaTransactionManager”
114. depends-on=”userTransactionService”>
115. <property name=”transactionManager” ref=”AtomikosTransactionManager” />
116. <property name=”userTransaction” ref=”AtomikosUserTransaction” />
117. </bean>
118.
119. <bean id=”user1Dao” class=”com.crm.code.dao.impl.User1DaoImpl”>
120. <property name=”sqlMapClient”>
121. <ref bean=”sqlMapClient1″/>
122. </property>
123. </bean>
124. <bean id=”user2Dao” class=”com.crm.code.dao.impl.User2DaoImpl”>
125. <property name=”sqlMapClient”>
126. <ref bean=”sqlMapClient2″/>
127. </property>
128. </bean>
129. <bean id=”user12Service” class=”com.crm.code.service.impl.User12ServiceImpl”>
130. <property name=”user1Dao”>
131. <ref bean=”user1Dao” />
132. </property>
133. <property name=”user2Dao”>
134. <ref bean=”user2Dao” />
135. </property>
136. </bean>
137.
138. </beans>
<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”> <bean id=”dataSource” class=”com.atomikos.jdbc.SimpleDataSourceBean” init-method=”init” destroy-method=”close”> <property name=”uniqueResourceName”> <value>mysql/main</value> </property> <property name=”xaDataSourceClassName”> <!–使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)–> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name=”xaDataSourceProperties”> <value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value> </property> <property name=”exclusiveConnectionMode”> <value>true</value> </property> <property name=”connectionPoolSize”> <value>3</value> </property> <property name=”validatingQuery”> <value>SELECT 1</value> </property> </bean> <!– 第二个数据库 –> <bean id=”dataSourceB” class=”com.atomikos.jdbc.SimpleDataSourceBean” init-method=”init” destroy-method=”close”> <property name=”uniqueResourceName”> <value>mysql/news</value> </property> <property name=”xaDataSourceClassName”> <!– 使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource) –> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name=”xaDataSourceProperties”> <value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value> </property> <property name=”exclusiveConnectionMode”> <value>true</value> </property> <property name=”connectionPoolSize”> <value>3</value> </property> <property name=”validatingQuery”> <value>SELECT 1</value> </property> </bean> <bean id=”lobHandler” class=”org.springframework.jdbc.support.lob.DefaultLobHandler” /> <!– 第一个数据库的sqlMapClient –> <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig.xml</value> </property> <property name=”dataSource” ref=”dataSource” /> <property name=”lobHandler” ref=”lobHandler” /> </bean> <!– 第二个数据库的sqlMapClient –> <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig2.xml</value> </property> <property name=”dataSource” ref=”dataSourceB” /> <property name=”lobHandler” ref=”lobHandler” /> </bean> <!– Optional: add a log administrator –> <bean id=”localLogAdministrator” class=”com.atomikos.icatch.admin.imp.LocalLogAdministrator”/> <bean id=”userTransactionService” class=”com.atomikos.icatch.config.UserTransactionServiceImp” init-method=”init” destroy-method=”shutdownForce”> <constructor-arg> <!– IMPORTANT: specify all Atomikos properties here –> <props> <prop key=”com.atomikos.icatch.service”>com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop> </props> </constructor-arg> <property name=”initialLogAdministrators”> <list> <ref bean=”localLogAdministrator”/> </list> </property> </bean> <!–Construct Atomikos UserTransactionManager,needed to configure Spring –> <bean id=”AtomikosTransactionManager” class=”com.atomikos.icatch.jta.UserTransactionManager” init-method=”init” destroy-method=”close” depends-on=”userTransactionService”> <!–when close is called,should we force transactions to terminate or not?–> <property name=”forceShutdown” value=”false” /> </bean> <!–Also use Atomikos UserTransactionImp, needed to configure Spring–> <bean id=”AtomikosUserTransaction” class=”com.atomikos.icatch.jta.UserTransactionImp” depends-on=”userTransactionService”> <property name=”transactionTimeout” value=”300″ /> </bean> <!– Configure the Spring framework to use JTA transactions from Atomikos –> <bean id=”JtaTransactionManager” class=”org.springframework.transaction.jta.JtaTransactionManager” depends-on=”userTransactionService”> <property name=”transactionManager” ref=”AtomikosTransactionManager” /> <property name=”userTransaction” ref=”AtomikosUserTransaction” /> </bean> <bean id=”user1Dao” class=”com.crm.code.dao.impl.User1DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient1″/> </property> </bean> <bean id=”user2Dao” class=”com.crm.code.dao.impl.User2DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient2″/> </property> </bean> <bean id=”user12Service” class=”com.crm.code.service.impl.User12ServiceImpl”> <property name=”user1Dao”> <ref bean=”user1Dao” /> </property> <property name=”user2Dao”> <ref bean=”user2Dao” /> </property> </bean> </beans>
这样是成功的 可是切换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.
— Check the insert into boss_product (PROD_ID, PARENT_ID, APP_ID, PROD_NAME, PROD_CODE, DEFAULT_VER_PROD_ID, DATA_PATH, GMT_CREATED, GMT_MODIFIED, CREATOR, MODIFIER, IS_DELETED) values (seq_boss_product.nextval, 1, 88, ?, ?, 10, ‘aaa’, sysdate, sysdate, ‘aavv’, ‘aacb’, ‘n’)
官方说oracle连接问题 哎。。。无语了
换了一种JTA事务机制 通过JOTM
view plaincopy to clipboardprint?
1. <?xml version=”1.0″ encoding=”UTF-8″?>
2. <beans xmlns=”http://www.springframework.org/schema/beans”
3. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop”
4. xmlns:tx=”http://www.springframework.org/schema/tx”
5. xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”>
8.
9. <bean id=”jotm” class=”org.springframework.transaction.jta.JotmFactoryBean”/>
10. <bean id=”txManager” class=”org.springframework.transaction.jta.JtaTransactionManager”>
11. <property name=”userTransaction” ref=”jotm”/>
12. </bean>
13.
14. <bean id=”dataSourceA” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource”
15. destroy-method=”shutdown”>
16. <property name=”dataSource”>
17. <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”>
18. <property name=”transactionManager” ref=”jotm”/>
19. <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/>
20. <property name=”url” value=”jdbc:oracle:thin:@10.2.224.44:1521:trade”/>
21. </bean>
22. </property>
23. <property name=”user” value=”crm_aep”/>
24. <property name=”password” value=”crm_aep”/>
25. </bean>
26.
27. <bean id=”dataSourceB” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource”
28. destroy-method=”shutdown”>
29. <property name=”dataSource”>
30. <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”>
31. <property name=”transactionManager” ref=”jotm”/>
32. <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/>
33. <property name=”url” value=”jdbc:oracle:thin:@10.2.226.24:1521:voucher”/>
34. </bean>
35. </property>
36. <property name=”user” value=”boss”/>
37. <property name=”password” value=”boss”/>
38. </bean>
39.
40. <tx:annotation-driven transaction-manager=”txManager” proxy-target-class=”true” />
41.
42. <!– 第一个数据库的sqlMapClient –>
43. <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
44. <property name=”configLocation”>
45. <!– 包含第一个数据库表的map –>
46. <value>classpath:SqlMapConfig_ora1.xml</value>
47. </property>
48. <property name=”dataSource” ref=”dataSourceA” />
49. </bean>
50. <!– 第二个数据库的sqlMapClient –>
51. <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
52. <property name=”configLocation”>
53. <!– 包含第一个数据库表的map –>
54. <value>classpath:SqlMapConfig_ora2.xml</value>
55. </property>
56. <property name=”dataSource” ref=”dataSourceB” />
57. </bean>
58.
59. <bean id=”product1Dao” class=”com.crm.code.dao.impl.Product1DaoImpl”>
60. <property name=”sqlMapClient”>
61. <ref bean=”sqlMapClient1″/>
62. </property>
63. </bean>
64. <bean id=”product2Dao” class=”com.crm.code.dao.impl.Product2DaoImpl”>
65. <property name=”sqlMapClient”>
66. <ref bean=”sqlMapClient2″/>
67. </property>
68. </bean>
69. <bean id=”product12Service” class=”com.crm.code.service.impl.Product12ServiceImpl”>
70. <property name=”product1Dao”>
71. <ref bean=”product1Dao” />
72. </property>
73. <property name=”product2Dao”>
74. <ref bean=”product2Dao” />
75. </property>
76. </bean>
77. </beans>
<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”> <bean id=”jotm” class=”org.springframework.transaction.jta.JotmFactoryBean”/> <bean id=”txManager” class=”org.springframework.transaction.jta.JtaTransactionManager”> <property name=”userTransaction” ref=”jotm”/> </bean> <bean id=”dataSourceA” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource” destroy-method=”shutdown”> <property name=”dataSource”> <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”> <property name=”transactionManager” ref=”jotm”/> <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/> <property name=”url” value=”jdbc:oracle:thin:@10.2.224.44:1521:trade”/> </bean> </property> <property name=”user” value=”crm_aep”/> <property name=”password” value=”crm_aep”/> </bean> <bean id=”dataSourceB” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource” destroy-method=”shutdown”> <property name=”dataSource”> <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”> <property name=”transactionManager” ref=”jotm”/> <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/> <property name=”url” value=”jdbc:oracle:thin:@10.2.226.24:1521:voucher”/> </bean> </property> <property name=”user” value=”boss”/> <property name=”password” value=”boss”/> </bean> <tx:annotation-driven transaction-manager=”txManager” proxy-target-class=”true” /> <!– 第一个数据库的sqlMapClient –> <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig_ora1.xml</value> </property> <property name=”dataSource” ref=”dataSourceA” /> </bean> <!– 第二个数据库的sqlMapClient –> <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig_ora2.xml</value> </property> <property name=”dataSource” ref=”dataSourceB” /> </bean> <bean id=”product1Dao” class=”com.crm.code.dao.impl.Product1DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient1″/> </property> </bean> <bean id=”product2Dao” class=”com.crm.code.dao.impl.Product2DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient2″/> </property> </bean> <bean id=”product12Service” class=”com.crm.code.service.impl.Product12ServiceImpl”> <property name=”product1Dao”> <ref bean=”product1Dao” /> </property> <property name=”product2Dao”> <ref bean=”product2Dao” /> </property> </bean> </beans>
成功了。。。
很好很好 哈哈哈
发表于 @ 2010年05月05日 12:06:00 | 评论( 0 ) | 编辑| 举报| 收藏
旧一篇:spring 多数据源 JTA 事务 | 新一篇:禁止页面的选择和复制功能
注:本文引自http://malaqu.com/?p=542
最近一个项目要跨多数据,配多数据源的,其中就用到了事务,毫无疑问我选择的是Spring的声明式JTA事务。我的环境是JBOSS+ORACLE 9I
自己私下做了些实验,不过还是成功了
实验一:MySQL 5.0
采用atomikos的jta事务(要感谢 http://andyao.iteye.com/)
view plaincopy to clipboardprint?
1. <?xml version=”1.0″ encoding=”UTF-8″?>
2. <beans xmlns=”http://www.springframework.org/schema/beans”
3. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop”
4. xmlns:tx=”http://www.springframework.org/schema/tx”
5. xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”>
8.
9. <bean id=”dataSource” class=”com.atomikos.jdbc.SimpleDataSourceBean”
10. init-method=”init” destroy-method=”close”>
11. <property name=”uniqueResourceName”>
12. <value>mysql/main</value>
13. </property>
14. <property name=”xaDataSourceClassName”>
15. <!–使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)–>
16. <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
17. </property>
18. <property name=”xaDataSourceProperties”>
19. <value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value>
20. </property>
21. <property name=”exclusiveConnectionMode”>
22. <value>true</value>
23. </property>
24. <property name=”connectionPoolSize”>
25. <value>3</value>
26. </property>
27. <property name=”validatingQuery”>
28. <value>SELECT 1</value>
29. </property>
30. </bean>
31. <!– 第二个数据库 –>
32. <bean id=”dataSourceB” class=”com.atomikos.jdbc.SimpleDataSourceBean”
33. init-method=”init” destroy-method=”close”>
34. <property name=”uniqueResourceName”>
35. <value>mysql/news</value>
36. </property>
37. <property name=”xaDataSourceClassName”>
38. <!–
39. 使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)
40. –>
41. <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
42. </property>
43. <property name=”xaDataSourceProperties”>
44. <value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value>
45. </property>
46. <property name=”exclusiveConnectionMode”>
47. <value>true</value>
48. </property>
49. <property name=”connectionPoolSize”>
50. <value>3</value>
51. </property>
52. <property name=”validatingQuery”>
53. <value>SELECT 1</value>
54. </property>
55. </bean>
56.
57. <bean id=”lobHandler” class=”org.springframework.jdbc.support.lob.DefaultLobHandler” />
58.
59. <!– 第一个数据库的sqlMapClient –>
60. <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
61. <property name=”configLocation”>
62. <!– 包含第一个数据库表的map –>
63. <value>classpath:SqlMapConfig.xml</value>
64. </property>
65. <property name=”dataSource” ref=”dataSource” />
66. <property name=”lobHandler” ref=”lobHandler” />
67. </bean>
68. <!– 第二个数据库的sqlMapClient –>
69. <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
70. <property name=”configLocation”>
71. <!– 包含第一个数据库表的map –>
72. <value>classpath:SqlMapConfig2.xml</value>
73. </property>
74. <property name=”dataSource” ref=”dataSourceB” />
75. <property name=”lobHandler” ref=”lobHandler” />
76. </bean>
77.
78. <!– Optional: add a log administrator –>
79. <bean id=”localLogAdministrator”
80. class=”com.atomikos.icatch.admin.imp.LocalLogAdministrator”/>
81.
82. <bean id=”userTransactionService”
83. class=”com.atomikos.icatch.config.UserTransactionServiceImp”
84. init-method=”init” destroy-method=”shutdownForce”>
85. <constructor-arg>
86. <!– IMPORTANT: specify all Atomikos properties here –>
87. <props>
88. <prop key=”com.atomikos.icatch.service”>com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
89. </props>
90. </constructor-arg>
91. <property name=”initialLogAdministrators”>
92. <list>
93. <ref bean=”localLogAdministrator”/>
94. </list>
95. </property>
96. </bean>
97. <!–Construct Atomikos UserTransactionManager,needed to configure Spring –>
98. <bean id=”AtomikosTransactionManager”
99. class=”com.atomikos.icatch.jta.UserTransactionManager”
100. init-method=”init” destroy-method=”close”
101. depends-on=”userTransactionService”>
102. <!–when close is called,should we force transactions to terminate or not?–>
103. <property name=”forceShutdown” value=”false” />
104. </bean>
105. <!–Also use Atomikos UserTransactionImp, needed to configure Spring–>
106. <bean id=”AtomikosUserTransaction”
107. class=”com.atomikos.icatch.jta.UserTransactionImp”
108. depends-on=”userTransactionService”>
109. <property name=”transactionTimeout” value=”300″ />
110. </bean>
111. <!– Configure the Spring framework to use JTA transactions from Atomikos –>
112. <bean id=”JtaTransactionManager”
113. class=”org.springframework.transaction.jta.JtaTransactionManager”
114. depends-on=”userTransactionService”>
115. <property name=”transactionManager” ref=”AtomikosTransactionManager” />
116. <property name=”userTransaction” ref=”AtomikosUserTransaction” />
117. </bean>
118.
119. <bean id=”user1Dao” class=”com.crm.code.dao.impl.User1DaoImpl”>
120. <property name=”sqlMapClient”>
121. <ref bean=”sqlMapClient1″/>
122. </property>
123. </bean>
124. <bean id=”user2Dao” class=”com.crm.code.dao.impl.User2DaoImpl”>
125. <property name=”sqlMapClient”>
126. <ref bean=”sqlMapClient2″/>
127. </property>
128. </bean>
129. <bean id=”user12Service” class=”com.crm.code.service.impl.User12ServiceImpl”>
130. <property name=”user1Dao”>
131. <ref bean=”user1Dao” />
132. </property>
133. <property name=”user2Dao”>
134. <ref bean=”user2Dao” />
135. </property>
136. </bean>
137.
138. </beans>
<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”> <bean id=”dataSource” class=”com.atomikos.jdbc.SimpleDataSourceBean” init-method=”init” destroy-method=”close”> <property name=”uniqueResourceName”> <value>mysql/main</value> </property> <property name=”xaDataSourceClassName”> <!–使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)–> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name=”xaDataSourceProperties”> <value>URL=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value> </property> <property name=”exclusiveConnectionMode”> <value>true</value> </property> <property name=”connectionPoolSize”> <value>3</value> </property> <property name=”validatingQuery”> <value>SELECT 1</value> </property> </bean> <!– 第二个数据库 –> <bean id=”dataSourceB” class=”com.atomikos.jdbc.SimpleDataSourceBean” init-method=”init” destroy-method=”close”> <property name=”uniqueResourceName”> <value>mysql/news</value> </property> <property name=”xaDataSourceClassName”> <!– 使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource) –> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name=”xaDataSourceProperties”> <value>URL=jdbc:mysql://localhost:3306/crm2?useUnicode=true&characterEncoding=UTF-8;user=root;password=root</value> </property> <property name=”exclusiveConnectionMode”> <value>true</value> </property> <property name=”connectionPoolSize”> <value>3</value> </property> <property name=”validatingQuery”> <value>SELECT 1</value> </property> </bean> <bean id=”lobHandler” class=”org.springframework.jdbc.support.lob.DefaultLobHandler” /> <!– 第一个数据库的sqlMapClient –> <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig.xml</value> </property> <property name=”dataSource” ref=”dataSource” /> <property name=”lobHandler” ref=”lobHandler” /> </bean> <!– 第二个数据库的sqlMapClient –> <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig2.xml</value> </property> <property name=”dataSource” ref=”dataSourceB” /> <property name=”lobHandler” ref=”lobHandler” /> </bean> <!– Optional: add a log administrator –> <bean id=”localLogAdministrator” class=”com.atomikos.icatch.admin.imp.LocalLogAdministrator”/> <bean id=”userTransactionService” class=”com.atomikos.icatch.config.UserTransactionServiceImp” init-method=”init” destroy-method=”shutdownForce”> <constructor-arg> <!– IMPORTANT: specify all Atomikos properties here –> <props> <prop key=”com.atomikos.icatch.service”>com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop> </props> </constructor-arg> <property name=”initialLogAdministrators”> <list> <ref bean=”localLogAdministrator”/> </list> </property> </bean> <!–Construct Atomikos UserTransactionManager,needed to configure Spring –> <bean id=”AtomikosTransactionManager” class=”com.atomikos.icatch.jta.UserTransactionManager” init-method=”init” destroy-method=”close” depends-on=”userTransactionService”> <!–when close is called,should we force transactions to terminate or not?–> <property name=”forceShutdown” value=”false” /> </bean> <!–Also use Atomikos UserTransactionImp, needed to configure Spring–> <bean id=”AtomikosUserTransaction” class=”com.atomikos.icatch.jta.UserTransactionImp” depends-on=”userTransactionService”> <property name=”transactionTimeout” value=”300″ /> </bean> <!– Configure the Spring framework to use JTA transactions from Atomikos –> <bean id=”JtaTransactionManager” class=”org.springframework.transaction.jta.JtaTransactionManager” depends-on=”userTransactionService”> <property name=”transactionManager” ref=”AtomikosTransactionManager” /> <property name=”userTransaction” ref=”AtomikosUserTransaction” /> </bean> <bean id=”user1Dao” class=”com.crm.code.dao.impl.User1DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient1″/> </property> </bean> <bean id=”user2Dao” class=”com.crm.code.dao.impl.User2DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient2″/> </property> </bean> <bean id=”user12Service” class=”com.crm.code.service.impl.User12ServiceImpl”> <property name=”user1Dao”> <ref bean=”user1Dao” /> </property> <property name=”user2Dao”> <ref bean=”user2Dao” /> </property> </bean> </beans>
这样是成功的 可是切换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.
— Check the insert into boss_product (PROD_ID, PARENT_ID, APP_ID, PROD_NAME, PROD_CODE, DEFAULT_VER_PROD_ID, DATA_PATH, GMT_CREATED, GMT_MODIFIED, CREATOR, MODIFIER, IS_DELETED) values (seq_boss_product.nextval, 1, 88, ?, ?, 10, ‘aaa’, sysdate, sysdate, ‘aavv’, ‘aacb’, ‘n’)
官方说oracle连接问题 哎。。。无语了
换了一种JTA事务机制 通过JOTM
view plaincopy to clipboardprint?
1. <?xml version=”1.0″ encoding=”UTF-8″?>
2. <beans xmlns=”http://www.springframework.org/schema/beans”
3. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop”
4. xmlns:tx=”http://www.springframework.org/schema/tx”
5. xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”>
8.
9. <bean id=”jotm” class=”org.springframework.transaction.jta.JotmFactoryBean”/>
10. <bean id=”txManager” class=”org.springframework.transaction.jta.JtaTransactionManager”>
11. <property name=”userTransaction” ref=”jotm”/>
12. </bean>
13.
14. <bean id=”dataSourceA” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource”
15. destroy-method=”shutdown”>
16. <property name=”dataSource”>
17. <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”>
18. <property name=”transactionManager” ref=”jotm”/>
19. <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/>
20. <property name=”url” value=”jdbc:oracle:thin:@10.2.224.44:1521:trade”/>
21. </bean>
22. </property>
23. <property name=”user” value=”crm_aep”/>
24. <property name=”password” value=”crm_aep”/>
25. </bean>
26.
27. <bean id=”dataSourceB” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource”
28. destroy-method=”shutdown”>
29. <property name=”dataSource”>
30. <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”>
31. <property name=”transactionManager” ref=”jotm”/>
32. <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/>
33. <property name=”url” value=”jdbc:oracle:thin:@10.2.226.24:1521:voucher”/>
34. </bean>
35. </property>
36. <property name=”user” value=”boss”/>
37. <property name=”password” value=”boss”/>
38. </bean>
39.
40. <tx:annotation-driven transaction-manager=”txManager” proxy-target-class=”true” />
41.
42. <!– 第一个数据库的sqlMapClient –>
43. <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
44. <property name=”configLocation”>
45. <!– 包含第一个数据库表的map –>
46. <value>classpath:SqlMapConfig_ora1.xml</value>
47. </property>
48. <property name=”dataSource” ref=”dataSourceA” />
49. </bean>
50. <!– 第二个数据库的sqlMapClient –>
51. <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
52. <property name=”configLocation”>
53. <!– 包含第一个数据库表的map –>
54. <value>classpath:SqlMapConfig_ora2.xml</value>
55. </property>
56. <property name=”dataSource” ref=”dataSourceB” />
57. </bean>
58.
59. <bean id=”product1Dao” class=”com.crm.code.dao.impl.Product1DaoImpl”>
60. <property name=”sqlMapClient”>
61. <ref bean=”sqlMapClient1″/>
62. </property>
63. </bean>
64. <bean id=”product2Dao” class=”com.crm.code.dao.impl.Product2DaoImpl”>
65. <property name=”sqlMapClient”>
66. <ref bean=”sqlMapClient2″/>
67. </property>
68. </bean>
69. <bean id=”product12Service” class=”com.crm.code.service.impl.Product12ServiceImpl”>
70. <property name=”product1Dao”>
71. <ref bean=”product1Dao” />
72. </property>
73. <property name=”product2Dao”>
74. <ref bean=”product2Dao” />
75. </property>
76. </bean>
77. </beans>
<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”> <bean id=”jotm” class=”org.springframework.transaction.jta.JotmFactoryBean”/> <bean id=”txManager” class=”org.springframework.transaction.jta.JtaTransactionManager”> <property name=”userTransaction” ref=”jotm”/> </bean> <bean id=”dataSourceA” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource” destroy-method=”shutdown”> <property name=”dataSource”> <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”> <property name=”transactionManager” ref=”jotm”/> <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/> <property name=”url” value=”jdbc:oracle:thin:@10.2.224.44:1521:trade”/> </bean> </property> <property name=”user” value=”crm_aep”/> <property name=”password” value=”crm_aep”/> </bean> <bean id=”dataSourceB” class=”org.enhydra.jdbc.pool.StandardXAPoolDataSource” destroy-method=”shutdown”> <property name=”dataSource”> <bean class=”org.enhydra.jdbc.standard.StandardXADataSource” destroy-method=”shutdown”> <property name=”transactionManager” ref=”jotm”/> <property name=”driverName” value=”oracle.jdbc.driver.OracleDriver”/> <property name=”url” value=”jdbc:oracle:thin:@10.2.226.24:1521:voucher”/> </bean> </property> <property name=”user” value=”boss”/> <property name=”password” value=”boss”/> </bean> <tx:annotation-driven transaction-manager=”txManager” proxy-target-class=”true” /> <!– 第一个数据库的sqlMapClient –> <bean id=”sqlMapClient1″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig_ora1.xml</value> </property> <property name=”dataSource” ref=”dataSourceA” /> </bean> <!– 第二个数据库的sqlMapClient –> <bean id=”sqlMapClient2″ class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”> <property name=”configLocation”> <!– 包含第一个数据库表的map –> <value>classpath:SqlMapConfig_ora2.xml</value> </property> <property name=”dataSource” ref=”dataSourceB” /> </bean> <bean id=”product1Dao” class=”com.crm.code.dao.impl.Product1DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient1″/> </property> </bean> <bean id=”product2Dao” class=”com.crm.code.dao.impl.Product2DaoImpl”> <property name=”sqlMapClient”> <ref bean=”sqlMapClient2″/> </property> </bean> <bean id=”product12Service” class=”com.crm.code.service.impl.Product12ServiceImpl”> <property name=”product1Dao”> <ref bean=”product1Dao” /> </property> <property name=”product2Dao”> <ref bean=”product2Dao” /> </property> </bean> </beans>
成功了。。。
很好很好 哈哈哈
发表于 @ 2010年05月05日 12:06:00 | 评论( 0 ) | 编辑| 举报| 收藏
旧一篇:spring 多数据源 JTA 事务 | 新一篇:禁止页面的选择和复制功能
发表评论
-
会话Bean 开发
2011-04-07 20:34 756会话Bean能分为有状态会 ... -
容器管理事务
2011-04-07 20:21 1218容器管理事务 http://www.i ... -
我们针对各种全异的数据源开发实体 EJB 的经验
2011-04-07 20:20 959我们针对各种全异的数 ... -
EJB 编程模型
2011-04-07 20:03 951EJB 编程模型 2009-2-26 ... -
权衡 Apache Geronimo EJB 事务选项,第 1 部分: 容器管理事务
2011-04-07 18:14 941权衡 Apache Geronimo EJB 事务选项,第 1 ...
相关推荐
本资源针对的是Spring Boot动态多数据源和JTA(Java Transaction API)分布式事务的实现,对于初学者来说非常实用。下面我们将深入探讨这些知识点。 首先,让我们了解一下Spring Boot的多数据源。在许多业务场景下...
XA协议是数据库层面的一套分布式事务管理的规范,JTA是XA协议在Java中的实现,多个数据库或是消息厂商实现JTA接口,开发人员只需要调用SpringJTA接口即可实现JTA事务管理功能。 JTA事务比JDBC事务更强大。一个JTA事务...
这篇博客"多数据源事务jta测试"可能探讨了如何在Java环境中利用JTA来实现对不同数据库的事务一致性。 JTA允许应用程序进行分布式事务处理,这意味着一个事务可以跨越多个数据库或者其他事务资源。这对于那些需要在...
本项目使用Spring Boot、Atomikos、JTA(Java Transaction API)、Hibernate和MySQL来实现分布式事务处理和多数据源管理,以确保在多个数据库操作之间保持事务的ACID特性。 首先,Spring Boot作为微服务开发的主流...
在多数据源场景下,SpringBoot允许我们配置多个数据源,这在分布式系统或者数据库分片场景中非常实用。 Atomikos是一个开源的事务管理器,它实现了Java Transaction API (JTA),支持全局事务处理。在分布式系统中,...
本案例主要探讨如何利用Spring Boot、Atomikos、JTA(Java Transaction API)、Hibernate以及MyBatis,结合MySQL数据库,实现一个跨数据源的分布式事务解决方案。 首先,Spring Boot是一个基于Spring框架的快速开发...
本文将深入探讨如何使用Spring、Java Transaction API (JTA) 和 Java Object Transaction Manager (JOTM) 实现多数据源更新的解决方案。 首先,让我们理解什么是多数据源。在传统的单数据源环境中,应用程序通常...
本文将深入探讨如何配置和使用Spring Boot与JTA来管理多个数据库的数据源事务。 首先,JTA是Java平台企业版(Java EE)的一部分,它提供了一种标准的方式来管理和协调跨多个数据存储的事务。在Spring Boot中,我们...
Druid是一个优秀的数据库连接池,它提供了监控、SQL解析、拦截器等功能,对于多数据源支持,Druid可以通过DataSourceProxy和AbstractRoutingDataSource配合使用。MyBatis是轻量级的持久层框架,与Spring整合后,可以...
本教程将探讨如何利用Spring Boot、Druid、Mybatis以及Atomikos来配置多数据源并实现分布式事务。 首先,Spring Boot是Java生态系统中的一个流行框架,它简化了设置和配置过程,使得开发人员可以快速启动新项目。在...
首先,分布式数据源是在多数据库环境下的一个重要概念。当业务需求扩大,单一数据库无法满足负载或者数据隔离的要求时,分布式数据源提供了一种解决方案。它允许我们将数据分布到多个物理数据库上,通过负载均衡和...
本示例项目"spring+mybatis+jta实现多数据源的分布式事务"提供了一种解决方案,利用Spring框架、MyBatis持久层框架以及Java Transaction API (JTA)来处理跨多个数据源的事务一致性。以下是对这一技术栈及其应用的...
而多数据源支持则是Spring框架在大型企业级应用中不可或缺的一个特性,尤其是在分布式系统或者需要对不同数据库进行操作的应用场景下。Atomikos是一个开源的事务管理器,专门用于处理分布式事务,它在Spring多数据源...
综上所述,这个项目展示了如何在 Spring MVC、MyBatis 和 JTA 的环境中配置和使用多数据源,实现了跨数据库的事务一致性,这对于大型分布式系统来说是非常重要的。同时,它还提供了一个测试环境,确保了配置的有效性...
在使用JTA时,你需要确保MyBatis的数据源配置为JNDI数据源,以便于事务的统一管理。 总的来说,Spring配置JTA事务管理是一项关键任务,它确保了在分布式环境下的数据一致性。理解并正确配置JTA事务管理,能够让你的...
通过Spring的配置,我们可以轻松地管理多个数据源,并根据业务逻辑进行动态切换。这通常涉及到使用`@Qualifier`注解来指定特定的数据源。 2. **Druid数据源** Druid是一个高性能、监控和扩展性极强的数据库连接池...
### Spring多数据源配置详解 在企业级应用中,尤其是微服务架构下,多数据源配置成为了一项常见的需求。Spring框架提供了灵活且强大的机制来处理这种场景,使得开发者能够在一个应用中集成多个数据源,从而实现数据...
1.多数据源配置,采用方式:直接配置两个不同的数据源,不同的sessionFactory。 2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元...
JTA是Java平台标准的一部分,用于管理跨多个数据源(如数据库、消息队列等)的事务。 在Spring框架中,JTA事务管理主要用于处理分布式系统中的事务,确保数据的一致性和完整性。Spring提供了两种主要的方式来实现...
SpringBoot作为一款轻量级的框架,提供了便捷的多数据源配置和分布式事务管理方案,使得开发者能够高效地管理和操作不同的数据库。本文将详细探讨SpringBoot如何实现多数据源以及分布式事务。 首先,我们要理解什么...