Sample-jta-spring » History » Revision 4
« Previous |
Revision 4/16
(diff)
| Next »
Henning Blohm, 27.09.2012 22:19
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.
Prerequisites¶
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:
cd $DERBY_INSTALL
java -jar lib/derbyrun.jar server start
On Windows run
cd %DERBY_INSTALL
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 http://git.z2-environment.net/z2-base.core
git clone -b master http://git.z2-environment.net/z2-samples.jta-spring
# on Linux / Mac OS:
cd z2-base.core/run/bin
./gui.sh
# on Windows:
cd z2-base.core\run\bin
gui.bat
Verifying¶
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...¶
So, here are the details and why this sample is interesting.
Until that part has been written (sorry) - please checkout the sample. If you are familiar with Spring and have a slight idea about JTA, you should see the beauty of it.
Updated by Henning Blohm about 12 years ago · 4 revisions