Sample-jta-spring » History » Revision 6

« Previous | Revision 6/15 (diff) | Next »
Henning Blohm, 01.05.2014 13:37

Using a Spring configured full-blown transaction manager across modules in Z2

As does Samples-jta-plain, so does this sample demonstrate how to use Z2 with the Atomikos transaction manager. In this case however, we choose to use the Spring framework to configure the transaction manager and enable re-use using Z2's support for modular Spring applications (see also How to Spring).

The Wiki page How_to_TransactionManager explains the general principles behind transaction handling in Z2.

This sample is stored in z2-samples.jta-spring. It implements exactly the same scenario as Sample-spring-hibernate with the exception of not using the built-in JTA implementation.


You need to run Java DB as network server on localhost. This is explained next.

The application will create a database "z2-samples"

Running a Java DB Network Server

Previously to Java 9, the Java SE Development Kit (JDK) by Oracle provided the Java DB - essentially the same as the Apache Derby DB. That is not the case anymore. However, we use that Database implementation in our samples. In order to run those samples that illustrate use of a relational database, please follow the instructions below to install and run Apache Derby. Could hardly be simpler.

Step 1: Download and Install

Unless you have done so already, download Apache Derby DB and follow the installation how-to.

Note: You do not need to unpack Apache Derby into some global folder on your system. Instead you may want to use some local folder under your user's home folder. There is no problem installing and runnning different instances and configurations at any time.

Step 2: Run

Let's assume you installed (well - unpacked) into a folder $DERBY_INSTALL. Also, let's assume some Java Runtime Environment is installed and ready.

Simply run the following on Linux or Mac OS:

java -jar lib/derbyrun.jar server start

On Windows run

java -jar lib\derbyrun.jar server start

That's it. Apache Derby will be waiting for connections on port 1527.

Running the sample

This sample is run as explained in How to run a sample. The 5 minutes version:

mkdir install
cd install 
git clone -b master
git clone -b master

# on Linux / Mac OS:
cd z2-base.core/run/bin

# on Windows:
cd z2-base.core\run\bin


When everything is up, go to http://localhost:8080/jta-spring. You see something like this:

And indeed, it's the same database we use elsewhere.

Now to the point...

This sample illustrates how to use a third-party transaction manager, the Atomikos implementation in this case, in a modular application as indicated in How_to_TransactionManager. This in conjunction with Spring resulting in a full-blown, highly adaptable and completely modular environment, scalable in deployment and development.

Updated by Henning Blohm about 8 years ago · 6 revisions