summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/documentation-2x/sca-java-implementationspring.html
blob: 50948d1cf4daf542671bcc7cfdf208248e4be376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
           <META name="description" content="Apache Tuscany">
   <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture,  sca, service component architecture, das, sdo, csa, ruby, opensource">

        <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
        <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/$images/favicon.ico">   
        <TITLE>SCA Java implementation.spring : Apache Tuscany</TITLE>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>

   <STYLE>
    .spacetree * ul {
       padding-left:0px;
       margin-left: 0px;
    }
    .spacetree * li {
       margin-left: 5px;
       padding-left:5px;
    }
   </STYLE>

    <BODY onload="init()">
            <!-- topNav -->
    <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
      <TR class="topBar">
        <TD align="left" valign="middle" class="topBarDiv" align="left" nowrap="">
          <A href="https://cwiki.apache.org/geronimo"> Home</A> &gt;&nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java implementation.spring">SCA Java implementation.spring</A>
        </TD>
        <TD align="right" valign="middle" nowrap="">
          <FORM name="search" action="http://www.google.com/search" method="get">
            <INPUT type="hidden" name="ie" value="UTF-8">
            <INPUT type="hidden" name="oe" value="UTF-8">
            <INPUT type="hidden" name="domains" value="">
            <INPUT type="hidden" name="sitesearch" value="">
            <INPUT type="text" name="q" maxlength="255" value="">        
            <INPUT type="submit" name="btnG" value="Google Search">
          </FORM>
        </TD>
      </TR> 
    </TABLE>

        
    <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
        <TR class="topBar">
            <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
                &nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java implementation.spring">SCA Java implementation.spring</A>
            </TD>

            <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
            <A href="http://tuscany.apache.org/">Tuscany Home</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
            </TD>
        </TR>
    </TABLE>

        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
            <TR>
                <TD valign="top" align="left" width="22%" bgcolor="#F9F9F9" class="noprint">
                        <DIV class="tabletitle">Table of Contents</DIV>
        <DIV class="spacetree">
            
            
            </DIV>
                </TD>
                <TD align="left" valign="top" width="78%">
                        <!-- pageContent -->
    <DIV id="PageContent">
      <DIV class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="http://geronimo.apache.org/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany Docs 2.x</DIV>
        <DIV style="margin: 0px 10px 8px 10px" class="pagetitle">SCA Java implementation.spring</DIV>

        <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
<!-- -->         
            <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=5964931">
            <IMG src="http://geronimo.apache.org/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
            <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=5964931">Edit Page</A>
          &nbsp;
          <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">
            <IMG src="http://geronimo.apache.org/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A>
            <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">Browse Space</A>
          &nbsp;
          <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964931">
            <IMG src="http://geronimo.apache.org/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A>
          <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964931">Add Page</A>
          &nbsp;
          <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964931">
            <IMG src="http://geronimo.apache.org/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A>
          <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964931">Add News</A>
<!-- -->	 
        </DIV>
      </DIV>

      <DIV class="pagecontent">
        <DIV class="wiki-content">
          <H2><A name="SCAJavaimplementation.spring-%3Cimplementation.spring%3E"></A>&lt;implementation.spring&gt;</H2>

<P>The Tuscany Java SCA runtime supports components implemented with Spring Framework by using the &lt;implementation.spring&gt; SCDL extension.</P>

<P>The <A href="http://www.osoa.org/download/attachments/35/SCA_SpringComponentImplementationSpecification-V100.pdf?version=1" class="external-link" rel="nofollow">Spring specification</A> defines how Spring and SCA work with one another. The Spring Component implementation is one of the SCA extensions which is being formalized in the OASIS Open Composite Services Architecture with a published <A href="http://www.oasis-opencsa.org/sca-spring" class="external-link" rel="nofollow">specifications </A> document.</P>

<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> In <A href="http://static.springframework.org/spring/docs/2.5.5/reference" class="external-link" rel="nofollow">Spring Framework</A> an ApplicationContext is the main interface to the Spring IoC container. It is used to look up objects. It can be viewed as the Java object representation of the application-Context.xml file that contains the bean definitions.</P>

<P>The integration with Spring will be at the SCA Composite level, where a Spring application context provides a complete composite, exposing services and using references via SCA. This means that a Spring application context defines the internal structure of a SCA composite implementation.</P>

<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> Tuscany uses Spring Framework 3.0.x-RELEASE (requires Java 1.4+)</P>

<H3><A name="SCAJavaimplementation.spring-HowSpringApplicationContextisusedasSCACompositeImplementation%3F"></A>How Spring Application Context is used as SCA Composite Implementation?</H3>

<UL>
	<LI>A Spring Application Context is used as an implementation within an SCA composite component.</LI>
	<LI>A component that uses Spring for an implementation can wire SCA services and references without introducing SCA metadata into the Spring configuration.<BR>
The Spring context knows very little about the SCA environment.</LI>
	<LI>SCA runtime enforces SCA policies and Spring Application Context is unaware of it.</LI>
	<LI>It should be possible to generate an SCA Composite from any Spring context and use that composite within an SCA assembly.<BR>
<EM>This feature is under review by the OASIS Specs Team, yet to be implemented in Tuscany</EM></LI>
</UL>


<H3><A name="SCAJavaimplementation.spring-HowtoUseSpringComponentImplementation%3F"></A>How to Use Spring Component Implementation?</H3>

<P>The Spring component implementation SCDL has the following format:</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">   &lt;implementation.spring location=<SPAN class="code-quote">&quot;targetURI&quot;</SPAN> /&gt;
</PRE>
</DIV></DIV>

<P>Where the location attribute of that element specifies the target uri of an archive file or directory or the fully qualified path that contains the Spring application context files.</P>

<P>An example of all the three ways of specifying the target uri in the location attribute is shown below</P>

<P>a) Specifying Fully Qualified Path:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">   &lt;implementation.spring location=<SPAN class="code-quote">&quot;./spring/application-context.xml&quot;</SPAN> /&gt;
</PRE>
</DIV></DIV>

<P>b) Specifying a Directory:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">   &lt;implementation.spring location=<SPAN class="code-quote">&quot;./spring&quot;</SPAN> /&gt;
</PRE>
</DIV></DIV>

<P>Here the target uri specifies the resource as a directory named &quot;spring&quot;, where all the spring related files are available.</P>

<P>c) Specifying an Archive file:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">   &lt;implementation.spring location=<SPAN class="code-quote">&quot;./spring.jar&quot;</SPAN> /&gt;
</PRE>
</DIV></DIV>

<P>Here the target uri specifies the resource as an archive file name &quot;spring.jar&quot;, where all the spring related files are available.</P>

<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> In case of b) and c), If the resource identified by the location attribute is an archive file then the file META-INF/MANIFEST.MF is read from the archive. If the location URI identifies a directory, then META-INF/MANIFEST.MF must exist underneath that directory.</P>

<P>If the manifest file contains a header &quot;Spring-Context&quot; of the format: <INS>Spring-Context ::= path ( ';' path )&#42;</INS></P>

<P>Where path is a relative path with respect to the location URI, then the set of paths specified in the header identify the context configuration files. If there is no MANIFEST.MF file or no Spring-Context header within that file, then the default behavior is to build an application context using application-context.xml file in the META-INF/spring directory.</P>

<H3><A name="SCAJavaimplementation.spring-HowSpringApplicationContextisAwareofBeansusedinSCAcomposition%3F"></A>How Spring Application Context is Aware of Beans used in SCA composition?</H3>

<P>Your existing Spring Application context should define the <A href="http://www.springframework.org/schema/sca" class="external-link" rel="nofollow">http://www.springframework.org/schema/sca</A> namespace in order to make the Spring aware of the SCA related beans. This is shown below.</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;beans xmlns=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//www.springframework.org/schema/beans&quot;</SPAN>
</SPAN>       xmlns:xsi=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//www.w3.org/2001/XMLSchema-instance&quot;</SPAN>
</SPAN>       xmlns:sca=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//www.springframework.org/schema/sca&quot;</SPAN>
</SPAN>       xsi:schemaLocation=&quot;
       http:<SPAN class="code-comment">//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
</SPAN>       http:<SPAN class="code-comment">//www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd&quot;&gt;
</SPAN>
    &lt;sca:service name=<SPAN class="code-quote">&quot;StockQuoteService&quot;</SPAN>
        type=<SPAN class="code-quote">&quot;bigbank.stockquote.StockQuoteService&quot;</SPAN> target=<SPAN class="code-quote">&quot;StockQuoteServiceBean&quot;</SPAN>/&gt;

    &lt;bean id=<SPAN class="code-quote">&quot;StockQuoteServiceBean&quot;</SPAN> class=<SPAN class="code-quote">&quot;bigbank.stockquote.StockQuoteImpl&quot;</SPAN>&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</PRE>
</DIV></DIV>


<H3><A name="SCAJavaimplementation.spring-HandlingmultipleSpringApplicationContexts"></A>Handling multiple Spring Application Contexts</H3>

<P>Tuscany supports the following configurations to handle multiple Spring Application Context XML files.</P>

<H4><A name="SCAJavaimplementation.spring-Using%3Cimport%3EElement%3A"></A>Using &lt;import&gt; Element:</H4>

<P>Each import element points to an application context xml file.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;beans&gt;
    &lt;<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">&quot;services.xml&quot;</SPAN>/&gt;
    &lt;<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">&quot;resources/messageSource.xml&quot;</SPAN>/&gt;

    &lt;<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">&quot;/resources/themeSource.xml&quot;</SPAN>/&gt;

    &lt;bean id=<SPAN class="code-quote">&quot;bean1&quot;</SPAN> class=<SPAN class="code-quote">&quot;...&quot;</SPAN>/&gt;
    &lt;bean id=<SPAN class="code-quote">&quot;bean2&quot;</SPAN> class=<SPAN class="code-quote">&quot;...&quot;</SPAN>/&gt;
&lt;/beans&gt;
</PRE>
</DIV></DIV>

<H4><A name="SCAJavaimplementation.spring-UsingClassPathXmlApplicationContextBeanDefinition%3A"></A>Using ClassPathXmlApplicationContext Bean Definition:</H4>

<P>Each list value points to an application context xml file.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;bean id=<SPAN class="code-quote">&quot;beanRefFactory&quot;</SPAN> class=<SPAN class="code-quote">&quot;org.springframework.context.support.ClassPathXmlApplicationContext&quot;</SPAN>&gt;
    &lt;constructor-arg&gt;
        &lt;list&gt;
            &lt;value&gt;services.xml&lt;/value&gt;
            &lt;value&gt;resources/messageSource.xml&lt;/value&gt;
        &lt;/list&gt;
    &lt;/constructor-arg&gt;
&lt;/bean&gt;
</PRE>
</DIV></DIV>

<H3><A name="SCAJavaimplementation.spring-SomeExamples%3A"></A>Some Examples:</H3>

<H4><A name="SCAJavaimplementation.spring-SpringBigBankSample"></A>Spring BigBank Sample</H4>

<P>The spring-bigbank sample demonstrates most of the functionality that is specified in the <A href="http://www.oasis-opencsa.org/sca-spring" class="external-link" rel="nofollow">specifications </A>.</P>

<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/simple-bigbank-spring/" class="external-link" rel="nofollow">simple-bigbank-spring </A> sample for a complete example.</P>

<H4><A name="SCAJavaimplementation.spring-DirectuseofSCAreferenceswithinaSpringconfiguration"></A>Direct use of SCA references within a Spring configuration</H4>

<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-calculator/" class="external-link" rel="nofollow">spring-bigbank-calculator </A> sample for a complete example of using direct SCA references within Spring configuration.</P>

<P>The properties like addService, subtractService, multiplyService and divideService defined in the Spring configuration as shown below</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;beans&gt;

    &lt;sca:service name=<SPAN class="code-quote">&quot;CalculatorService&quot;</SPAN>
        type=<SPAN class="code-quote">&quot;bigbank.calculator.CalculatorService&quot;</SPAN> target=<SPAN class="code-quote">&quot;CalculatorServiceBean&quot;</SPAN>/&gt;

    &lt;bean id=<SPAN class="code-quote">&quot;CalculatorServiceBean&quot;</SPAN> class=<SPAN class="code-quote">&quot;bigbank.calculator.CalculatorServiceImpl&quot;</SPAN>&gt;
        &lt;!-- Here are some implicit references - a property with a ref not satisifed within the
         * Spring application context.
         --&gt;
        &lt;property name=<SPAN class="code-quote">&quot;addService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;addService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;subtractService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;subtractService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;multiplyService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;multiplyService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;divideService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;divideService&quot;</SPAN>/&gt;
    &lt;/bean&gt;

&lt;/beans&gt;
</PRE>
</DIV></DIV>

<P>are the direct representation of the SCA references defined in the composite file.</P>

<H4><A name="SCAJavaimplementation.spring-ExplicitdeclarationofSCArelatedbeansinsideaSpringApplicationContext"></A>Explicit declaration of SCA related beans inside a Spring Application Context</H4>

<P>It is also possible to explicitly declare SCA-related beans inside a Spring configuration to proxy SCA references. The primary reason you may do this is to enable the Spring container to decorate the bean (using Spring AOP for example).</P>

<P>The properties checkingAccountService, calculatorService and stockQuoteService defined in the Spring configuration as shown below</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;beans&gt;
   &lt;bean id=<SPAN class="code-quote">&quot;AccountServiceBean&quot;</SPAN> class=<SPAN class="code-quote">&quot;bigbank.account.AccountServiceImpl&quot;</SPAN>&gt;
        &lt;property name=<SPAN class="code-quote">&quot;calculatorService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;calculatorService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;stockQuoteService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;stockQuoteService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;checkingAccountService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;checkingAccountService&quot;</SPAN>/&gt;

        &lt;!-- Here are some implicit references &amp; properties - a property with a ref not satisifed
        * within the Spring application context.
         --&gt;
        &lt;property name=<SPAN class="code-quote">&quot;savingsAccountService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;savingsAccountService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;stockAccountService&quot;</SPAN> ref=<SPAN class="code-quote">&quot;stockAccountService&quot;</SPAN>/&gt;
        &lt;property name=<SPAN class="code-quote">&quot;currency&quot;</SPAN> value=<SPAN class="code-quote">&quot;EURO&quot;</SPAN>/&gt;
    &lt;/bean&gt;

    &lt;sca:reference name=<SPAN class="code-quote">&quot;checkingAccountService&quot;</SPAN> type=<SPAN class="code-quote">&quot;bigbank.account.checking.CheckingAccountService&quot;</SPAN>/&gt;

    &lt;sca:reference name=<SPAN class="code-quote">&quot;calculatorService&quot;</SPAN> type=<SPAN class="code-quote">&quot;bigbank.calculator.CalculatorService&quot;</SPAN>/&gt;

    &lt;sca:reference name=<SPAN class="code-quote">&quot;stockQuoteService&quot;</SPAN> type=<SPAN class="code-quote">&quot;bigbank.stockquote.StockQuoteService&quot;</SPAN>/&gt;
&lt;/beans&gt;
</PRE>
</DIV></DIV>

<P>can be declared explicit as SCA beans in Spring Application Context using the &lt;sca:reference&gt; element.</P>

<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/simple-bigbank-spring/" class="external-link" rel="nofollow">simple-bigbank-spring </A> sample for a complete example of using explicit declaration of SCA related beans.</P>

<H4><A name="SCAJavaimplementation.spring-UsingSCABindingsforSpringImplementation"></A>Using SCA Bindings for Spring Implementation</H4>

<P>We know that a component that uses Spring for an implementation can wire SCA services and references without introducing SCA metadata into the Spring configuration. The Spring context knows very little about the SCA environment. Hence the SpringComponent implementation remains the same as shown from some of the examples above but different bindings are chosen at the SCA Composite level as shown below.</P>

<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> All kind of bindings supported by SCA can be used for Spring Implementation as the bindings are independent of Spring context. Few examples can be seen below.</P>

<H5><A name="SCAJavaimplementation.spring-WorkingwithSCAWebServicesBinding"></A>Working with SCA WebServices Binding</H5>

<P>Declaring Service</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;composite name=<SPAN class="code-quote">&quot;StockQuote&quot;</SPAN>&gt;

    &lt;service name=<SPAN class="code-quote">&quot;StockQuoteService&quot;</SPAN> promote=<SPAN class="code-quote">&quot;StockQuoteServiceComponent&quot;</SPAN>&gt;
        &lt;<SPAN class="code-keyword">interface</SPAN>.java <SPAN class="code-keyword">interface</SPAN>=<SPAN class="code-quote">&quot;bigbank.stockquote.StockQuoteService&quot;</SPAN>/&gt;
        &lt;binding.ws uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8081/services/StockQuoteWebService&quot;</SPAN>/&gt;
</SPAN>    &lt;/service&gt;

    &lt;component name=<SPAN class="code-quote">&quot;StockQuoteServiceComponent&quot;</SPAN>&gt;
        &lt;implementation.spring location=<SPAN class="code-quote">&quot;META-INF/spring/StockQuoteService-context.xml&quot;</SPAN>/&gt;
    &lt;/component&gt;

&lt;/composite&gt;
</PRE>
</DIV></DIV>

<P>Declaring Reference in a component which consumes the Service declared above</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;component name=<SPAN class="code-quote">&quot;AccountServiceComponent&quot;</SPAN>&gt;
    &lt;implementation.spring location=<SPAN class="code-quote">&quot;spring-context/Account-spring-context.xml&quot;</SPAN>/&gt;

    &lt;reference name=<SPAN class="code-quote">&quot;stockQuoteService&quot;</SPAN>&gt;
       &lt;binding.ws uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8081/services/StockQuoteWebService&quot;</SPAN>/&gt;
</SPAN>    &lt;/reference&gt;
&lt;/component&gt;
</PRE>
</DIV></DIV>

<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-stockquote/" class="external-link" rel="nofollow">spring-bigbank-stockquote </A> sample for a complete example of using SCA Web Service binding.</P>

<H5><A name="SCAJavaimplementation.spring-WorkingwithSCARMIBinding"></A>Working with SCA RMI Binding</H5>

<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-calculator/" class="external-link" rel="nofollow">spring-bigbank-calculator </A> sample for a complete example of using SCA RMI binding.</P>

<H3><A name="SCAJavaimplementation.spring-AccesstheSpringApplicationContextfromeverywhereinyourApplication"></A>Access the Spring-ApplicationContext from everywhere in your Application</H3>

<P>Tuscany creates an custom Application context with an implementation logic for all SCA related beans like &lt;sca:service&gt;, &lt;sca:reference&gt; and &lt;sca:properties&gt; available in the Spring Application Context.</P>

<P>To access the application context in your application we recommend to use the suggested approach in this article.<BR>
<A href="http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/" class="external-link" rel="nofollow">http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/</A></P>


<H3><A name="SCAJavaimplementation.spring-NonSupportedFeaturesinTuscany"></A>Non-Supported Features in Tuscany</H3>

<P>Currently Tuscany does not support implicit SCA references and properties for scenario 1 &amp; 2 in spring context as shown below.</P>

<H5><A name="SCAJavaimplementation.spring-Scenario1%3AUsingimplicitSCAReferences%26PropertiesforConstructors"></A>Scenario 1: Using implicit SCA References &amp; Properties for Constructors</H5>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;constructor-arg&gt;&lt;ref bean=<SPAN class="code-quote">&quot;mySCAService1&quot;</SPAN>/&gt;&lt;/constructor-arg&gt;
&lt;constructor-arg&gt;&lt;ref bean=<SPAN class="code-quote">&quot;mySCAService2&quot;</SPAN>/&gt;&lt;/constructor-arg&gt;
</PRE>
</DIV></DIV>

<P>In the above scenario, particularly in cases where the spring bean has defined only one constructor, implicit references / properties can be supported when the contructor-arg element specifies the type of the SCA reference/property that its trying to consume by specifying a type attribute in the contructor-arg OR when the appropriate index attribute is specified in the constructor-arg element.</P>

<P>In cases where the spring bean has defined multiple contructors, its mandatory that all the SCA references / properties used by the constructors should be defined explicitly. And when the constructor-arg uses SCA reference/property within collections, those should be defined explicitly.</P>

<H5><A name="SCAJavaimplementation.spring-Scenario2%3AUsingimplicitSCAReferences%26PropertiesinList%2CMapandSetofbeanproperties."></A>Scenario 2: Using implicit SCA References &amp; Properties in List, Map and Set of bean properties.</H5>

<P>Using implicit SCA references and properties within collection as shown in the below code sample will not be supported by Tuscany. Instead we recommed to use explicit SCA references/properties in such cases.</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">&lt;bean id=<SPAN class="code-quote">&quot;moreComplexObject&quot;</SPAN> class=<SPAN class="code-quote">&quot;example.ComplexObject&quot;</SPAN>&gt;
  &lt;!-- results in a setSomeList(java.util.List) call --&gt;
  &lt;property name=<SPAN class="code-quote">&quot;someList&quot;</SPAN>&gt;
    &lt;list&gt;
        &lt;value&gt;a list element followed by a reference&lt;/value&gt;
        &lt;ref bean=<SPAN class="code-quote">&quot;mySCAService1&quot;</SPAN> /&gt;
    &lt;/list&gt;
  &lt;/property&gt;
  &lt;!-- results in a setSomeMap(java.util.Map) call --&gt;
  &lt;property name=<SPAN class="code-quote">&quot;someMap&quot;</SPAN>&gt;
    &lt;map&gt;
        &lt;entry&gt;
            &lt;key&gt;
                &lt;value&gt;an entry&lt;/value&gt;
            &lt;/key&gt;
            &lt;value&gt;just some string&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key&gt;
                &lt;value&gt;a ref&lt;/value&gt;
            &lt;/key&gt;
            &lt;ref bean=<SPAN class="code-quote">&quot;mySCAService2&quot;</SPAN> /&gt;
        &lt;/entry&gt;
    &lt;/map&gt;
  &lt;/property&gt;
  &lt;!-- results in a setSomeSet(java.util.Set) call --&gt;
  &lt;property name=<SPAN class="code-quote">&quot;someSet&quot;</SPAN>&gt;
    &lt;set&gt;
        &lt;value&gt;just some string&lt;/value&gt;
        &lt;ref bean=<SPAN class="code-quote">&quot;mySCAService3&quot;</SPAN> /&gt;
    &lt;/set&gt;
  &lt;/property&gt;
&lt;/bean&gt;
</PRE>
</DIV></DIV>

<H5><A name="SCAJavaimplementation.spring-Scenario3%3AExposingSCAServicefromSpringBeanthatimplementsmultipleinterfaces."></A>Scenario 3: Exposing SCA Service from Spring Bean that implements multiple interfaces.</H5>

<P>Raised as Specification Issue: <A href="http://www.osoa.org/jira/browse/JAVA-59" class="external-link" rel="nofollow">http://www.osoa.org/jira/browse/JAVA-59</A></P>


<H3><A name="SCAJavaimplementation.spring-IntegrationwithSpringforWebApplications%28includingSpringMVC%29"></A>Integration with Spring for Web Applications (including Spring MVC)</H3>



<P><A href="sca-java-implementationspring.data/Spring%20Tuscany.pptx">Presentation</A></P>


<H3><A name="SCAJavaimplementation.spring-SpringSCANamespaceschema"></A>Spring SCA Namespace schema</H3>

<P>The spring-sca.xsd can be found at the following location: <A href="http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd" class="external-link" rel="nofollow">http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd</A></P>


<H3><A name="SCAJavaimplementation.spring-References"></A>References</H3>

<P>Spring Framework - <A href="http://static.springframework.org/spring/docs/2.5.5/reference/index.html" class="external-link" rel="nofollow">http://static.springframework.org/spring/docs/2.5.5/reference/index.html</A></P>
        </DIV>

              </DIV>
    </DIV>
                </TD>
            </TR>
        </TABLE>

            <!-- footer -->
    <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
        <TR>
          <TD align="left" valign="middle" class="footer">
            &nbsp;&nbsp;
            <IMG src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious">
            <A href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'delicious','toolbar=no,width=550,height=550'); return false;">Bookmark this on Delicious</A>
            &nbsp;&nbsp;
            <IMG src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!">
            <A href="" onclick="window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&topic=programming');">Digg this</A>
            <!-- Slicker, but no text
            <script type="text/javascript">
              digg_skin = 'icon';
              digg_window = 'new';
              digg_title = 'Apache Geronimo v2.2 Documentation : SCA Java implementation.spring';
              digg_topic = 'programming';
            </script>
            <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
            -->
            &nbsp;&nbsp;
          </TD>
          <TD align="right" valign="middle" class="footer">
            <A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A>&nbsp;&nbsp;-&nbsp;&nbsp;
            Copyright &copy; 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>&nbsp;&nbsp;
          </TD>
        </TR>
    </TABLE> 

    </BODY>
</HTML>