Project

General

Profile

Sample-jta-spring » History » Version 16

Henning Blohm, 18.06.2023 13:01

1 3 Henning Blohm
h1. Using a Spring configured full-blown transaction manager across modules in Z2
2 1 Henning Blohm
3 7 Henning Blohm
As does [[Sample-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]]).
4 3 Henning Blohm
5
The Wiki page [[How_to_TransactionManager]] explains the general principles behind transaction handling in Z2.
6
7
This sample is stored in "z2-samples.jta-spring":http://redmine.z2-environment.net/projects/z2-samples/repository/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.
8
9
h2. Prerequisites
10
11 10 Henning Blohm
{{include(Java Version Requirements)}}
12 9 Henning Blohm
13 3 Henning Blohm
You need to run Java DB as network server on localhost. This is explained next.
14
15
The application will create a database "z2-samples"
16
17
{{include(How to run Java db)}}
18
19
h2. Running the sample
20
21 12 Henning Blohm
{{include(Install_sample_prefix)}}
22 1 Henning Blohm
23 12 Henning Blohm
Check out the sample
24 3 Henning Blohm
25 12 Henning Blohm
<pre><code class="ruby">
26 16 Henning Blohm
git clone -b v2.10 https://www.z2-environment.net/git/z2-samples.jta-spring
27 3 Henning Blohm
</code></pre>
28 12 Henning Blohm
29
{{include(Install_sample_postfix)}}
30 3 Henning Blohm
31
h2. Verifying
32
33 4 Henning Blohm
When everything is up, go to http://localhost:8080/jta-spring. You see something like this: 
34 3 Henning Blohm
35 5 Henning Blohm
!jta-spring-thingies.png!
36 8 Henning Blohm
tra
37 3 Henning Blohm
And indeed, it's the same database we use elsewhere.
38
39
h2. Now to the point...
40
41 1 Henning Blohm
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.
42 8 Henning Blohm
43
Unlike [[Sample-jta-plain]], Atomikos configuration and set up of transaction manager and user transaction is done by Spring. This may be perceived a more consistent approach by Spring users.
44
45
Instead of invoking the JTA Transaction Manager interface directly, transaction demarcation is done using Spring's \@Transactional annotation (in the "Controller":https://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-jta-spring/revisions/master/entry/com.zfabrik.samples.jta-spring.web/java/src.impl/com/zfabrik/samples/jta_spring/web/ControllerFilter.java). Note that Spring transaction de-marcation cannot be used with direct transaction manager usage at the same time (as Spring keeps additional context).