<?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">
<!-- 数据源1 -->
<bean id="dataSource1" 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/test?useUnicode=true&characterEncoding=utf-8;user=root;password=123456</value>
</property>
<property name="validatingQuery">
<value>SELECT 1</value>
</property>
</bean>
<!-- 数据源2 -->
<bean id="dataSource2" class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mysql/secondary</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/test2?useUnicode=true&characterEncoding=utf-8;user=root;password=123456</value>
</property>
<property name="validatingQuery">
<value>SELECT 1</value>
</property>
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="true"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300"/>
</bean>
<!-- JTA事务管理器 -->
<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<!-- 第一个sessionFactory,有多少个数据库就要有多少个数据源,也就要有多少个sessionFactory,每个sessionFactory对应一个数据源 -->
<bean id="sessionFactory1" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource1"/>
<property name="annotatedClasses">
<list>
<value>org.zsl.jta.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!--
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
-->
</props>
</property>
</bean>
分享到:
Global site tag (gtag.js) - Google Analytics
|
相关推荐
Spring boot+Atomikos+JTA+Hibernate+MySQL实现分布式事务+多数据源,分别向两个不同的数据里面插入数据同时失败和成功,调用接口方式原理一样。
2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 (特别注意:Spring3.0里不在提供对jotm的...
spring+hibernate+jta 分布式事务管理Demo源码(无jar包) 博文链接:https://momoko8443.iteye.com/blog/190994
spring hibernate jta 在MyEclipse下整合的完整DEMO,详细配置
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
springboot+Atomikos+jpa+mysql的JTA分布式事务实现,本案例涉及到2个数据库,预期结果,在同一个事务中,两个库的状态一致
NULL 博文链接:https://xnbhnly.iteye.com/blog/1547459
基于网上很多朋友在问JSF+Spring+Hibernate的使用方法,于是抽空写了个小例子希望大家提出宝贵意见。 采用DBUnit测试 mysql数据库脚本: 新建test数据库,初始化脚本 create table tt(id int primary key,name ...
全部业务控制交由Spring去进行处理。事务处理也交由Spring去管理。 压缩文件中不包含Jar文件(由于全部的Jar将近12M,不能全部上传),所用到的Jar目录为,工程中再也不会出现由于MyEclipse自动整合而出现的大量...
NULL 博文链接:https://hezhiyu.iteye.com/blog/1284415
該示例采用Strtus+Spring+Hibernate(簡稱SSH組合)實現一個簡單的電子公告板示例,演示了SSH組合在WEB中的一般應用,在這裡可以體驗到SSH組合清暫的分層,代碼簡潔清楚,各類文件之間的關係變得不再復雜了。...
完全由Spring接管DWR AJAX处理(不需要配置dwr.xml)等技术点 源码在/mytest/WEB-INF/src下 Winxp sp3+JDK1.6+Tomcat 6.0下运行通过 因文件长度限制,未加入相关类库,请自行加入,需要的类库有: dom.jar...
Struts2+Spring2.5.6+Hibernate3 用到的jar包 antlr-2.7.6.jar asm.jar backport-util-concurrent.jar cglib-nodep-2.1_3.jar commons-collections-3.1.jar commons-dbcp.jar commons-fileupload-1.2.1.jar commons-...
MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在...
-- JTA环境的事务配置 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager or WebLogicJtaTransactionManager"/> --> <!-- 使用annotation定义事务 --> ...