您的位置:首页 > 运维架构 > Tomcat

Spring+Tomcat+Atomikos + Druid 实现JTA

2016-09-13 22:41 323 查看
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>


以上配置出来再JEE环境中完美运行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring tomcat JTA Atomikos