JTA可以在多个数据库上使用一个事务,weblogic等应用服务器提供了jta数据源的支持,可以直接被使用。但是tomcat本身并不支持这种特性。如果想在tomcat上使用jta就必须使用其它的工具。jotm就是一个独立的可以提供JTA功能的组件。

<?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:context="http://www.springframework.org/schema/context"    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.5.xsd    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">  <description>springJTA</description>  <!--指定Spring配置中用到的属性文件    <bean id="propertyConfig"    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    <property name="locations">    <list>    <value>classpath:jdbc.properties</value>    </list>    </property>    </bean>       --><!-- JOTM实例 -->  <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean">  <property name="defaultTimeout" value="500000"/>  </bean>  <!-- JTA事务管理器 -->  <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">      <property name="userTransaction" ref="jotm" />      </bean>  <!-- 数据源A -->    <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="com.mysql.jdbc.Driver"/>    <property name="url" value="jdbc:mysql://localhost:3306/emp_mvc"/>    </bean>    </property>    <property name="user" value="root"/>    <property name="password" value="123456"/>    </bean>    <!-- 数据源B -->    <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="com.mysql.jdbc.Driver"/>    <property name="url" value="jdbc:mysql://localhost:3306/emp_mvc2"/>    </bean>    </property>    <property name="user" value="root"/>    <property name="password" value="123456"/>    </bean>    <bean id = "sessionFactoryA"    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name = "dataSource" ref="dataSourceA"/><property name="mappingResources"><list>        <value>com/ouku/JOTM/entity/Emp.hbm.xml</value></list></property>    </bean>  <bean id = "sessionFactoryB"    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">   <property name = "dataSource" ref="dataSourceB"/><property name="mappingResources"><list>        <value>com/ouku/JOTM/entity/Emp2.hbm.xml</value></list></property>    </bean>       <!-- 事务切面配置 -->    <aop:config>    <aop:pointcut id="pointCut"  expression="execution(* com.ouku.JOTM..*.*(..))"/><!-- 包及其子包下的所有方法 -->  <aop:advisor pointcut-ref="pointCut" advice-ref="txAdvice"/>    <aop:advisor pointcut="execution(* *..ouku.JOTM.*.*(..))" advice-ref="txAdvice"/>  </aop:config>    <!-- 通知配置 -->    <tx:advice id="txAdvice" transaction-manager="jtaTransactionManager">    <tx:attributes>    <tx:method name="delete*" rollback-for="Exception"/>    <tx:method name="save*" rollback-for="Exception"/>    <tx:method name="update*" rollback-for="Exception"/>    <tx:method name="find*" read-only="true" rollback-for="Exception"/>  <tx:method name="*" read-only="true" rollback-for="Exception"/>    </tx:attributes>    </tx:advice>    <bean id="genericDao"    class="com.ouku.JOTM.DAO.GenericDaoImpl" autowire="byName"> <property name="sessionFactoryA" ref="sessionFactoryA"></property> <property name="sessionFactoryB" ref="sessionFactoryB"></property> </bean>  <bean id="userService"    class="com.ouku.JOTM.biz.UserServiceImpl" autowire="byName">  </bean>  </beans>



本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1744796

Spring JTA事务配置JOTM相关推荐

  1. Spring MVC 事务配置

    Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法: 一.      XML,使用tx标签配置拦截器实现事务 一.   ...

  2. spring中事务配置的3种方式-2

    http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch09s05.html http://zpchen.iteye.com/blog/ ...

  3. spring中事务配置的3种方式

    http://xuxiaolei.iteye.com/blog/417803 (1)通过TransactionProxyFactoryBean来声明 Xml代码   <?xml version= ...

  4. 在Spring中使用JOTM实现JTA事务管理

    Spring 通过AOP技术可以让我们在脱离EJB的情况下享受声明式事务的丰盛大餐,脱离Java EE应用服务器使用声明式事务的道路已经畅通无阻.但是很大部分人都还认为脱离Java EE应用服务器就无 ...

  5. 在Spring中使用JTA事务管理

    在Spring中使用JTA事务管理 Spring 通过AOP技术可以让我们在脱离EJB的情况下享受声明式事务的丰盛大餐,脱离Java EE应用服务器使用声明式事务的道路已经畅通无阻.但是很大部分人都还 ...

  6. Spring JTA应用JOTM Atomikos II JOTM

    上节建立了一个简单的Java Application以及所需要的数据库和数据表,本节将介绍JOTM在Spring中的配置. JOTM(Java Open Transaction Manager)是Ob ...

  7. Spring事务配置的五种方式和spring里面事务的传播属性和事务隔离级别、不可重复读与幻读的区别

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. spring事务配置的五种方式 前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spr ...

  8. SSH深度历险(六) 深入浅出----- Spring事务配置的五种方式

    这对时间在学习SSH中Spring架构,Spring的事务配置做了具体总结.在此之间对Spring的事务配置仅仅是停留在听说的阶段,总结一下.总体把控.通过这次的学习发觉Spring的事务配置仅仅要把 ...

  9. spring事务配置

    2019独角兽企业重金招聘Python工程师标准>>> 前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识. ...

最新文章

  1. Android Studio SDK Manager 解决无法更新问题
  2. 简明python教程购买-自学Python买什么书?
  3. python读取excelsheet-一文看懂用Python读取Excel数据
  4. C语言 数字翻转输出
  5. cfile清空文件内容_电脑C盘文件夹哪些可以删除?教你如何快速清理,旧电脑还能用3年...
  6. express+mongodb+vue实现增删改查-全栈之路2.0
  7. 【转】HashTable 和 HashMap的区别
  8. 切点方法的事务参数的配置
  9. linux下jboss分析helloword,JBoss 中运行servlet 的helloworld程序(转)
  10. 大学生信息安全_给大学生的信息
  11. Linux time()函数解析
  12. python 进程通信 延时_Python-----进程通信队列
  13. Linux操作系统PS命令详细解析
  14. poj 1087.A Plug for UNIX (最大流)
  15. 微分方程数值计算matlab实现,微分方程数值解及Matlab实现
  16. 实时公交api接口-车来了公交接口-API公交接口 -如何接入
  17. 华为深圳数据分析外包
  18. win10 + chrome 死机问题处理
  19. 为什么变量命名不建议用汉语拼音
  20. 【原创】samba移植到android流程

热门文章

  1. 十:变量的定义和声明的区别?
  2. sEMG项目总结(5)sEMG分析
  3. 百度SEO合集 WordPress插件+seo优化插件+快速收录+网站蜘蛛
  4. Debian中ifconfig命令无法使用的问题
  5. 80个白色图标素材 psd
  6. 飞天软件锁Rockey1在软件产品中的应用
  7. 水墨印象中国风PPT模板
  8. 飞速低代码:解放IT生产力,推动社会数字化转型的加速器
  9. c语言m62429音量控制程序,音量控制M62446的驱动C程序
  10. JavaScript面试题看这一篇就够了,简单全面一发入魂(持续更新 step2)