<?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" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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/context
http://www.springframework.org/schema/context/spring-context-2.0.xsd">
<!-- <bean class="com.common.processor.PrivilegetHandler"></bean>
-->
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm"></property>
</bean>
<bean id="abstractTransactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean>
<bean id="abstractTmsSessionProxy" abstract="true">
<property name="sessionFactory" ref="tmsSessionFactory" />
</bean>
<bean id="abstractWmsSessionProxy" abstract="true">
<property name="sessionFactory" ref="wmsSessionFactory" />
</bean>
<bean id="abstractFmsSessionProxy" abstract="true">
<property name="sessionFactory" ref="fmsSessionFactory" />
</bean>
<!-- WMS data source -->
<bean id="innerDataSourceA" class="org.enhydra.jdbc.standard.StandardXADataSource"
destroy-method="shutdown">
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="driverName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://192.168.1.110:3306/test1?autoReconnect=true&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="dataSourceA" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
destroy-method="shutdown">
<property name="dataSource">
<ref local="innerDataSourceA" />
</property>
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="maxSize">
<value>10</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactoryA"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceA" />
<property name="mappingResources">
<list>
<value>com/systemmr/bean/hbm/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.transaction.factory_class">org.springframework.orm.hibernate3.SpringTransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.springframework.orm.hibernate3.LocalTransactionManagerLookup</prop>
<prop key="jta.UserTransaction">java:comp/UserTransaction</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jotm" />
</property>
</bean>
<!--TMS data source -->
<bean id="innerDateSourceB" class="org.enhydra.jdbc.standard.StandardXADataSource"
destroy-method="shutdown">
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="driverName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://192.168.1.110:3306/test2?autoReconnect=true&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="dataSourceB" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
destroy-method="shutdown">
<property name="dataSource">
<ref local="innerDateSourceB" />
</property>
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="maxSize">
<value>10</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactoryB"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceB" />
<property name="mappingResources">
<list>
<value>com/systemmr/bean/hbm/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.transaction.factory_class">org.springframework.orm.hibernate3.SpringTransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.springframework.orm.hibernate3.LocalTransactionManagerLookup</prop>
<prop key="jta.UserTransaction">java:comp/UserTransaction</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jotm" />
</property>
</bean>
<!-- 定义事务管理器,使用适用于Hibernte的事务管理器 -->
<!-- <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
HibernateTransactionManager bean需要依赖注入一个SessionFactory bean的引用
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="txManager" />
<property name="transactionAttributes">
<props>
<!-- 其他方法,采用required的事务策略 -->
<!-- <prop key="insert*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="update*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="save*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="add*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="edit*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="create*">PROPAGATION_REQUIRED</prop> -->
<!-- <prop key="delete*">PROPAGATION_REQUIRED</prop> -->
<!-- 所有以find开头的方法,采用required的事务策略,并且只读 -->
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="doQuery*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<!-- 此处增加新的Interceptor -->
</list>
</property>
</bean>
<!-- 定义DAO bean的事务代理 -->
<!-- <bean id="personDao" -->
<!-- class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> -->
<!-- 为事务代理bean注入事务管理器 -->
<!-- <property name="transactionManager"> -->
<!-- <ref bean="transactionManager" /> -->
<!-- </property> -->
<!-- 设置事务属性 -->
<!-- <property name="transactionAttributes"> -->
<!-- <props> -->
<!-- 所有以find开头的方法,采用required的事务策略,并且只读 -->
<!-- <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> -->
<!-- <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> -->
<!-- <prop key="doQuery*">PROPAGATION_REQUIRED,readOnly</prop> -->
<!-- <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop> -->
<!-- <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop> -->
<!-- 其他方法,采用required的事务策略 -->
<!-- <prop key="*">PROPAGATION_REQUIRED</prop> -->
<!-- </props> -->
<!-- </property> -->
<!-- 为事务代理bean设置目标bean -->
<!-- <property name="target"> -->
<!-- <ref local="basicDao" /> -->
<!-- </property> -->
<!-- </bean> -->
<!-- Autowired -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean id="hibernateTemplateA" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactoryA" />
</property>
</bean>
<bean id="hibernateTemplateB" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactoryB" />
</property>
</bean>
<bean id="testUserService" class="com.systemmr.service.impl.TestUserServiceImpl">
<property name="hibernateTemplateA" ref="hibernateTemplateA"></property>
<property name="hibernateTemplateB" ref="hibernateTemplateB"></property>
</bean>
</beans>
相关推荐
多数据源事务可采用jta+atomikos方式来解决事务问题。
通过multipleDataSource 解决多数据切换,并通过jta解决事务同步问题。先配置db.properties文件,再分别在数据库建测试表(user.sql),通过index2.jsp测试。
本资源包含了两个子项目,分别进行了springboot+jpa+jdbcTemplate的多数据源独立事务配置和jta分布式事务配置,并针对不同的情况编写了事务配置测试接口,还演示了JPA的domain一对多自动生成数据库表且不生成数据库...
该文件是给什么都不会的小白,下载下来进行简单的配置就可以运行,可以到https://blog.csdn.net/qq_43314669/article/details/106733829 进行在线观看
使用jta来管理多数据源的事物,代码整洁,一看就懂
博客上有很多类似的,很多都有点小错误。还是自己搭建测试的好用。resource中有sql,自己创建两个数据库导入sql,即可运行test测试
NULL 博文链接:https://malixxx.iteye.com/blog/560727
springboot+mybatis+jta+atomikos解决多数据源事务问题
多数据源 更新 spring jta java jotm
1.多数据源配置,采用方式:直接配置两个不同的数据源,不同的sessionFactory。 2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元...
springboot+jta+atomikos Springboot+atomikos+jta实现分布式事务统一管理
spring boot下学习mybatis+mysql使用jta对多数据源事务进行整合
使用springboot+jta+atomikos来配置多数据源下的事务分布管理 里面带有sql语句.直接下载下来,并且运行sql就可以测试运行
JTA分布式事务处理多数据事务问题的示例代码。
Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. 这个源码示例非常不错,包括所有的源码和jar包,下载后eclipse 或 myeclipse 导入就能用。 里面有详细的说明和注释,...
在Spring中使用JTA事务管理 1 通过集成JOTM,直接在Spring中使用JTA事务 1.1. 将JOTM以下类库添加到类路径中 1.2. 编写JOTM配置文件,放到类...2.3. 配置Tomcat环境,配置JNDI的数据源 2.4. Spring中相应的配置 3 小结
SSM多数据源同包
分布式数据源,数据源的动态寻找,分布式事务JTA实现-spring-jta-mybatis
Spring boot+Atomikos+JTA+Hibernate+MySQL实现分布式事务+多数据源,分别向两个不同的数据里面插入数据同时失败和成功,调用接口方式原理一样。
SpringBoot+Atomikos分布式事务及多数据源动态切换,两种demo,两条数据源,是满足事务唯一性的,看清楚是demo