Spring JTA multiple resource transactions in Tomcat with Atomikos example
Posted xiaobin-hlj80
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring JTA multiple resource transactions in Tomcat with Atomikos example相关的知识,希望对你有一定的参考价值。
http://www.byteslounge.com/tutorials/spring-jta-multiple-resource-transactions-in-tomcat-with-atomikos-example
Spring JTA multiple resource transactions in Tomcat with Atomikos example
Introduction
Distributed multiple resource transactions in Java are usually accomplished by resorting to the Java Transaction API (JTA). One usually delegates the task of distributed transaction coordination to an entity called the Transaction Manager.
The transaction manager is then responsible for coordinating the distributed transaction by interacting with each resource‘s own Resource Manager. Fully fledged enterprise containers include a JTA implementation but what if we need JTA outside an enterprise container, ie. a servlet container like Tomcat?
In this case we must use a 3rd party JTA implementation. In this tutorial we will use Atomikos, a quality JTA implementation which is also available as an open source distribution, along with the Spring framework in order to implement JTA transactions.
This tutorial considers the following environment:
- Ubuntu 12.04
- JDK 1.7.0.21
- Spring 3.2.3
- Atomikos 3.8.0
- Tomcat 7.0.35
The following Maven dependencies are required:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.3.RELEASE</spring.version>
<hibernate.version>4.1.9.Final</hibernate.version>
<atomikos.version>3.8.0</atomikos.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jta</artifactId>
<version>${atomikos.version}</version>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jdbc</artifactId>
<version>${atomikos.version}</version>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-hibernate3</artifactId>
<version>${atomikos.version}</version>
<exclusions>
<exclusion>
<artifactId>hibernate</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>