Spring+Tomcat+Atomikos + Druid 实现JTA

1 下载Atomikos所需的包 
下载地址:http://www.atomikos.com/Main/InstallingExtremeTransactions 
下载后如下: 
这里写图片描述
下载的其实是一个Maven的库 
2 将com下面的文件移动到自己的maven库里面,如果不是用maven进行搭建就拷贝相应的jar包 
移到本地maven库中如下: 
这里写图片描述
3 pom文件添加的 
这里写图片描述
atomikos.version=4.0.4.EVAL 
4 application.xml文件

<?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:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/jee
                        http://www.springframework.org/schema/jee/spring-jee.xsd">
    <context:component-scan base-package="com.itgo.*" />

    <bean id="dataSource" class="com.alibaba.druid.pool.xa.DruidXADataSource" init-method="init"     destroy-method="close"> 
         <property name="url" value="${jdbc_url}" />
         <property name="username" value="${jdbc_user}"/>
         <property name="password" value="${jdbc_password}" />
         <property name="maxActive" value="${maxActive}"/>

         <property name="filters"><value>stat</value></property>
         <property name="initialSize"><value>1</value></property>
         <property name="maxWait"><value>60000</value></property>
         <property name="minIdle"><value>1</value></property>

         <property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
         <property name="minEvictableIdleTimeMillis"><value>300000</value></property>

         <property name="validationQuery"><value>SELECT 'x'</value></property>
         <property name="testWhileIdle"><value>true</value></property>
         <property name="testOnBorrow"><value>false</value></property>
         <property name="testOnReturn"><value>false</value></property>

         <property name="poolPreparedStatements"><value>true</value></property>
         <property name="maxOpenPreparedStatements"><value>20</value></property>
    </bean>

    <bean id="atomikosDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
        <property name="uniqueResourceName" value="cdc2"/>
        <property name="xaDataSource" ref="dataSource"/>
    </bean>

     <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <property name="dataSource" ref="atomikosDataSource" />
      <property name="mapperLocations" value="classpath*:com/itgo/mxsm/mybatis/mysql/mapper/*.xml" />
    </bean>



    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.itgo.mxsm.mybatis.mysql.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sessionFactory" />
    </bean>

    <!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean> -->

    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
        <description>UserTransactionManager</description>
        <property name="forceShutdown" value="false" /> 
    </bean>

    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
        <property name="transactionTimeout" value="300" />
    </bean>

    <!-- <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> -->
    <bean id="JtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" >
        <property name="transactionManager" ref="atomikosTransactionManager" /> 
        <property name="userTransaction" ref="atomikosUserTransaction" /> 
    </bean>
    <tx:annotation-driven/>

</beans>
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77

以上配置出来再JEE环境中完美运行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值