How to Spring » History » Version 16
Henning Blohm, 06.09.2012 09:30
1 | 16 | Henning Blohm | <pre><code class="clojure"> |
---|---|---|---|
2 | # comment |
||
3 | x=a |
||
4 | |||
5 | y=b,\ |
||
6 | c |
||
7 | </code></pre> |
||
8 | |||
9 | <pre><code class="css"> |
||
10 | # comment |
||
11 | x=a |
||
12 | |||
13 | y=b,\ |
||
14 | c |
||
15 | </code></pre> |
||
16 | <pre><code class="delphi"> |
||
17 | # comment |
||
18 | x=a |
||
19 | |||
20 | y=b,\ |
||
21 | c |
||
22 | </code></pre> |
||
23 | <pre><code class="diff"> |
||
24 | # comment |
||
25 | x=a |
||
26 | |||
27 | y=b,\ |
||
28 | c |
||
29 | </code></pre> |
||
30 | <pre><code class="erb"> |
||
31 | # comment |
||
32 | x=a |
||
33 | |||
34 | y=b,\ |
||
35 | c |
||
36 | </code></pre> |
||
37 | <pre><code class="groovy"> |
||
38 | # comment |
||
39 | x=a |
||
40 | |||
41 | y=b,\ |
||
42 | c |
||
43 | </code></pre> |
||
44 | <pre><code class="haml"> |
||
45 | # comment |
||
46 | x=a |
||
47 | |||
48 | y=b,\ |
||
49 | c |
||
50 | </code></pre> |
||
51 | <pre><code class="php"> |
||
52 | # comment |
||
53 | x=a |
||
54 | |||
55 | y=b,\ |
||
56 | c |
||
57 | </code></pre> |
||
58 | <pre><code class="python"> |
||
59 | # comment |
||
60 | x=a |
||
61 | |||
62 | y=b,\ |
||
63 | c |
||
64 | </code></pre> |
||
65 | <pre><code class="ruby"> |
||
66 | # comment |
||
67 | x=a |
||
68 | |||
69 | y=b,\ |
||
70 | c |
||
71 | </code></pre> |
||
72 | |||
73 | |||
74 | 2 | Henning Blohm | h1. How to Use the Spring Framework in Z2 |
75 | |||
76 | There is actually nothing sooo particular about using Spring in Z2. But when knowing how Z2 modularity works, there is much to gain by spending a few minutes reading this How-To. However it is required that you are familiar with the Spring framework as such. |
||
77 | |||
78 | h2. Pre-Requisites |
||
79 | |||
80 | 3 | Henning Blohm | In order to have the Spring libraries available you need to add the repository _z2-addons.spring_ to your environment. Some samples, for example the z2-samples.jta-spring sample explained in [[How to TransactionManager]] does so. To use the master branch version, add a *springRepository.properties* component descriptor to your *environment* module saying |
81 | |||
82 | 15 | Henning Blohm | <pre><code class="delphi"> |
83 | 3 | Henning Blohm | com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up |
84 | |||
85 | # git stored component repository |
||
86 | com.zfabrik.component.type=com.zfabrik.gitcr |
||
87 | |||
88 | # true <=> optional repository. If gitcr.uri is invalid, then this gitcr will be ignore silently |
||
89 | gitcr.optional=true |
||
90 | |||
91 | # this can also point to a remote repository like |
||
92 | # ssh://myserver/some/git/repo |
||
93 | gitcr.uri=http://git.z2-environment.net/z2-addons.spring |
||
94 | |||
95 | # the git branch to use (e.g. 'master') |
||
96 | gitcr.branch=master |
||
97 | 15 | Henning Blohm | </code></pre> |
98 | 3 | Henning Blohm | |
99 | For your own system, you may need to adapt the repository URL and the branch selection accordingly. |
||
100 | |||
101 | If that sounds like meaningless gibberish to you - sorry please consult the documentation at http://www.z2-environment.eu/v20doc and go back to [[First_steps_with_z2]]. |
||
102 | |||
103 | 9 | Henning Blohm | |
104 | 4 | Henning Blohm | When you added that repository the following modules are available: |
105 | |||
106 | * org.springframework.orm |
||
107 | * org.springframework.security |
||
108 | * org.springframework.foundation |
||
109 | * org.springframework.transaction |
||
110 | * org.springframework.jdbc |
||
111 | * org.springframework.web |
||
112 | * com.zfabrik.springframework |
||
113 | * com.zfabrik.springframework.web |
||
114 | 1 | Henning Blohm | |
115 | |||
116 | With the exception of those starting with "com.zfabrik", these do, more or less, correspond to the typical Spring modules found out there. |
||
117 | 10 | Henning Blohm | |
118 | Before you get frustrated by the amount of details in this How-To, please remember that there is practical samples available to help you check how things can really be assembled to work nicely: |
||
119 | |||
120 | * z2-samples.jta-spring (LINK) |
||
121 | 4 | Henning Blohm | |
122 | 2 | Henning Blohm | h2. Using Spring in Web Applications |
123 | |||
124 | 5 | Henning Blohm | This is the simplest and really just the standard case. If you do not strive for re-use across modules that use Spring, then there is not much to worry about. |
125 | |||
126 | As usual, you define an application context in the WEB-INF folder of the Web application and set up a context listener in WEB-INF/web.xml to have the application |
||
127 | context initialized as the Web app is started. |
||
128 | |||
129 | 6 | Henning Blohm | In order to have the minimal set of dependencies satisfied - i.e. not assuming you want to use the (very cool) AspectJ based Spring configuration, you should _add_ (i.e. augment whatever refs you already have) the following references to *java/z.properties*: |
130 | 5 | Henning Blohm | |
131 | 14 | Henning Blohm | <pre><code class="java"> |
132 | 5 | Henning Blohm | java.privateReferences=\ |
133 | com.zfabrik.springframework.web,\ |
||
134 | org.springframework.foundation,\ |
||
135 | org.springframework.web |
||
136 | |||
137 | 11 | Henning Blohm | </code></pre> |
138 | 5 | Henning Blohm | |
139 | The reference to *com.zfabrik.springframework.web* is not strictly needed but adds the following capabilities: |
||
140 | |||
141 | 7 | Henning Blohm | * You implicitly get *com.zfabrik.springframework*, i.e. the integration features described below |
142 | 5 | Henning Blohm | |
143 | 7 | Henning Blohm | * You can use a parent application context to your Web application application context as easily as you would hope (see below). |
144 | |||
145 | |||
146 | |||
147 | |||
148 | 2 | Henning Blohm | h2. Using Spring in Re-use Modules |
149 | |||
150 | h2. Using Spring's Aspect/J Configuration |
||
151 | 7 | Henning Blohm | |
152 | h2. Using a Parent Application Context in a Web Application Application Context |
||
153 | |||
154 | Sometimes, later, when you find that your module has a web app but in addition you want to expose services, from the very same module, i.e. when you have spring configured objects in the web app but also a classpath defined application context that should serve as a _parent application context_ to the one of the web app (admittedly an advanced case), then you will find that that is slightly tricky to achieve (see e.g. http://blog.springsource.org/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/). |
||
155 | 8 | Henning Blohm | |
156 | 7 | Henning Blohm | The class *com.zfabrik.springframework.web.ComponentParentContextContextLoaderListener* is a drop-in replacement for Spring's ContextLoaderListener implementation that simplifies that use-case as explained in http://z2spring.z2-environment.net/javadoc/com.zfabrik.springframework.web!2Fjava/api/com/zfabrik/springframework/web/ComponentParentContextContextLoaderListener.html. |