Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
borderfalse
Column
width15%
Include Page
TUSCANYWIKI: Repeating Menu
TUSCANYWIKI: Repeating Menu
Include Page
TUSCANYWIKI: Java SCA Menu New
TUSCANYWIKI: Java SCA Menu New
Column
width85%

<implementation.spring>

The Tuscany Java SCA runtime supports components implemented with Spring Framework by using the <implementation.spring> SCDL extension.

Spring Framework are used with SCA by integration Spring 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 composite implementation.

The Spring Component implementation is one of the SCA extensions which is being formalized in the OASIS Open Composite Services Architecture with a published specifications document.

How Spring Application Context is used as SCA Composite Implementation?

  • A Spring Application Context is used as an implementation within an SCA composite component.
  • 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.
  • All policy enforcement occurs in the SCA runtime implementation and does not enter into theSpring space.
  • It should be possible to generate an SCA Composite from any Spring context and use that composite within an SCA assembly.

How to Use Spring Component Implementation

The Spring component implementation SCDL has the following format:

Code Block
   <implementation.spring location="targetURI" />

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.

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

a) Specifying Fully Qualified Path:

Code Block
   <implementation.spring location="./spring/application-context.xml" />

b) Specifying a Directory:

Code Block
   <implementation.spring location="./spring" />

Here the target uri specifies the resource as a directory named "spring", where all the spring related files are available.

c) Specifying an Archive file:

Code Block
   <implementation.spring location="./spring.jar" />

Here the target uri specifies the resource as an archive file name "spring.jar", where all the spring related files are available.

IMPORTANT NOTE: 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.

If the manifest file contains a header "Spring-Context" of the format: Spring-Context ::= path ( ';' path )*

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 behaviour is to build an application context using application-context.xml file in the META-INF/spring directory.

Some Examples:

Spring BigBank Sample

The spring-bigbank sample demonstrates most of the functionality that being specified in the specifications demostrating how the Spring Framework can be used with SCA.

See the simple-bigbank-spring sample for a complete example.

Direct use of SCA references within a Spring configuration

The references like addService, subtractService, multiplyService and divideService defined by SCA composite as shown below

How Spring Application Context is Aware of the SCA Related Beans?

Your existing Spring Application context should define the http://www.springframework.org/schema/sca namespace as shown below.

Code Block

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Code Block

<composite>

    <component name="CalculatorServiceComponent">
		<implementation.spring location="META-INF/spring/CalculatorService-context.xml"/> 

        <reference name="addService" target="AddServiceComponent" />
xmlns:sca="http://www.springframework.org/schema/sca"
       xsi:schemaLocation="
   <reference name="subtractService" target="SubtractServiceComponent" />
        <reference name="multiplyService" target="MultiplyServiceComponent" />   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        <reference name="divideService" target="DivideServiceComponent" /http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
    </component>
   
    <component<sca:service name="AddServiceComponentStockQuoteService">
        <tuscany:implementation.script scripttype="calculator/AddServiceImpl.jsbigbank.stockquote.StockQuoteService" target="StockQuoteServiceBean"/>
    </component>

    <component<bean nameid="SubtractServiceComponentStockQuoteServiceBean">
        <tuscany:implementation.script script="calculator/SubtractServiceImpl.rb"/ class="bigbank.stockquote.StockQuoteImpl">
    </component>bean>
</beans>

to make your application context aware of the SCA related beans.

Some Examples:

Spring BigBank Sample

The spring-bigbank sample demonstrates most of the functionality that being specified in the specifications demostrating how the Spring Framework can be used with SCA.

See the simple-bigbank-spring sample for a complete example.

Direct use of SCA references within a Spring configuration

The references like addService, subtractService, multiplyService and divideService defined by SCA composite as shown below

Code Block

<composite>
    <component name="MultiplyServiceComponent">
        <tuscany:implementation.script script="calculator/MultiplyServiceImpl.py"/>
    </component>

    <component name="DivideServiceComponentCalculatorServiceComponent">
        <tuscany:implementation.script script="calculator/DivideServiceImpl.groovy"/>		<implementation.spring location="META-INF/spring/CalculatorService-context.xml"/> 

    </component>

</composite>

can be directly used by Spring Application Context as shown here...

Code Block

<beans>

    <sca:service<reference name="CalculatorServiceaddService"
 target="AddServiceComponent" />
       type <reference name="bigbank.calculator.CalculatorServicesubtractService" target="CalculatorServiceBeanSubtractServiceComponent" />

        <bean<reference idname="CalculatorServiceBeanmultiplyService" classtarget="bigbank.calculator.CalculatorServiceImpl"MultiplyServiceComponent" />
        <!-- Here are some implicit references - a property with a ref not satisifed within the<reference name="divideService" target="DivideServiceComponent" />
    </component>

    <component name="AddServiceComponent">
         * Spring application context.<tuscany:implementation.script script="calculator/AddServiceImpl.js"/>
    </component>

     --<component name="SubtractServiceComponent">
        <property name="addService" ref="addService"<tuscany:implementation.script script="calculator/SubtractServiceImpl.rb"/>
    </component>

    <property<component name="subtractService" ref="subtractService"/MultiplyServiceComponent">
        <property name="multiplyService" ref="multiplyService"<tuscany:implementation.script script="calculator/MultiplyServiceImpl.py"/>
    </component>

    <property<component name="divideService" ref="divideService"/DivideServiceComponent">
      </bean>  <tuscany:implementation.script script="calculator/DivideServiceImpl.groovy"/>
    </component>

</beans>composite>

See the spring-bigbank-calculator sample for a complete example of using SCA references directly.

Explicit declaration of SCA related beans inside a Spring Application Context

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).

The references checkingAccountService, calculatorService and stockQuoteService defined by SCA composite as shown below

can be directly used by Spring Application Context as shown here...

Code Block

<beans>

    <sca:service name="CalculatorService"
Code Block

<composite name="BigBank">

    <component name="AccountServiceComponent">
        <implementation.spring location="spring-context/Account-spring-context.xmltype="bigbank.calculator.CalculatorService" target="CalculatorServiceBean"/>
        
    <bean    <service name="AccountServiceid="CalculatorServiceBean" class="bigbank.calculator.CalculatorServiceImpl">
        <!-- Here are  <interface.java interface="bigbank.account.AccountService"/>
        </service>

some implicit references - a property with a ref not satisifed within the
         * <reference name="savingsAccountService" target="SavingsAccountServiceComponent"/>
Spring application context.
         -->
        <reference<property name="checkingAccountService"addService" ref="addService"/>
        <property  <interface.java interface="bigbank.account.checking.CheckingAccountServicename="subtractService" ref="subtractService"/>
        <property  <binding.jms initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"name="multiplyService" ref="multiplyService"/>
        <property name="divideService" ref="divideService"/>
    </bean>

</beans>

See the spring-bigbank-calculator sample for a complete example of using SCA references directly.

Explicit declaration of SCA related beans inside a Spring Application Context

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).

The references checkingAccountService, calculatorService and stockQuoteService defined by SCA composite as shown below

Code Block

<composite name="BigBank">

    <component name="AccountServiceComponent">         jndiURL="tcp://localhost:61619">
              <destination name="RequestQueue" create="always"/>
              <response>
                  <destination name="ResponseQueue" create="always"/>
              </response> 
          </binding.jms><implementation.spring location="spring-context/Account-spring-context.xml"/>
        </reference>
        <service name="AccountService">
           <reference name="stockAccountService" target="StockAccountServiceComponent <interface.java interface="bigbank.account.AccountService"/>
        </service>

        <reference name="calculatorService"savingsAccountService" target="SavingsAccountServiceComponent"/>
        
      <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/ <reference name="checkingAccountService">
        </reference>      <interface.java interface="bigbank.account.checking.CheckingAccountService"/>
        
     <binding.jms initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
         <reference name="stockQuoteService">
            <binding.ws urijndiURL="httptcp://localhost:8081/services/StockQuoteWebService61619"/>
        </reference>
    </component>

  <destination  <component namename="RequestQueue" create="SavingsAccountServiceComponentalways"/>
         <implementation.composite name="bbsv:SavingsAccountDept"/>
     <response>
     </component>

    <component name="StockAccountServiceComponent">
        <implementation.composite<destination name="bbst:StockAccountDept"ResponseQueue" create="always"/>
              </component>

</composite>

can be declared explicit as SCA beans in Spring Application Context as shown below using the Spring SCA Namespace schema..

Code Block

<beans>
   <bean id="AccountServiceBean" class="bigbank.account.AccountServiceImpl">response> 
          </binding.jms>
        </reference>
        
        <property<reference name="calculatorServicestockAccountService" reftarget="calculatorServiceStockAccountServiceComponent"/>
        
 <property name="stockQuoteService" ref="stockQuoteService"/>
       <reference name="calculatorService">
          <property name="checkingAccountService" ref="checkingAccountService  <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
        
</reference>      
  <!-- Here are some implicit references &
 properties - a property with a ref not satisifed <reference name="stockQuoteService">
        * within the Spring application context.<binding.ws uri="http://localhost:8081/services/StockQuoteWebService"/>
         --></reference>
    </component>

    <property<component name="savingsAccountService" ref="savingsAccountService"/SavingsAccountServiceComponent">
        <property<implementation.composite name="stockAccountService" ref="stockAccountService"/>bbsv:SavingsAccountDept"/>
    </component>

           <component name="StockAccountServiceComponent">
        <property<implementation.composite name="currency" value="EURO"bbst:StockAccountDept"/>
    </component>

</composite>

can be declared explicit as SCA beans in Spring Application Context as shown below using the Spring SCA Namespace schema..

Code Block

<beans>
   <bean id="AccountServiceBean" classbean>
    
    <sca:reference name="checkingAccountService" type="bigbank.account.checking.CheckingAccountServiceAccountServiceImpl"/>     
    
    <sca:reference<property name="calculatorService" typeref="bigbank.calculator.CalculatorServicecalculatorService"/>
    
    <sca:reference<property name="stockQuoteService" typeref="bigbank.stockquote.StockQuoteService"stockQuoteService"/>
        <property name="checkingAccountService" ref="checkingAccountService"/>
</beans>

See the simple-bigbank-spring sample for a complete example of using explicit declaration of SCA related beans.

Using SCA Bindings for Spring Implementation

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.

NOTE: 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.

Working with SCA WebServices Binding

Declaring Service

Code Block

<composite name="StockQuote"        
        <!-- Here are some implicit references & properties - a property with a ref not satisifed 
        * within the Spring application context.
         -->
    
    <service<property name="StockQuoteServicesavingsAccountService" promoteref="StockQuoteServiceComponentsavingsAccountService"/>
        <interface.java interface="bigbank.stockquote.StockQuoteService"/>
<property name="stockAccountService" ref="stockAccountService"/>             <binding.ws uri="http://localhost:8081/services/StockQuoteWebService"/>
    </service>

    <component<property name="currency" value="StockQuoteServiceComponentEURO"/>
    </bean>
    <implementation.spring location="META-INF/spring/StockQuoteService-context.xml"/>
    </component>

</composite>

Declaring Reference

Code Block

<component<sca:reference name="AccountServiceComponentcheckingAccountService">
    <implementation.spring location="spring-context/Account-spring-context.xml type="bigbank.account.checking.CheckingAccountService"/>
    
    <reference<sca:reference name="stockQuoteService""calculatorService" type="bigbank.calculator.CalculatorService"/>
    
    <binding.ws uri="http://localhost:8081/services/StockQuoteWebService"/>
    </reference>
</component><sca:reference name="stockQuoteService" type="bigbank.stockquote.StockQuoteService"/>
</beans>

See the springsimple-bigbank-stockquote spring sample for a complete example of using SCA Web Service binding.

Working with SCA RMI Binding

Declaring Service

example of using explicit declaration of SCA related beans.

Using SCA Bindings for Spring Implementation

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.

NOTE: 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.

Working with SCA WebServices Binding

Declaring Service

Code Block

<composite name="StockQuote"
Code Block

<composite name="Calculator">
    <service name="CalculatorService" promote="CalculatorServiceComponent">
        <interface.java interface="bigbank.calculator.CalculatorService"/>
        <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
    </service>

    <component name="CalculatorServiceComponent">
        <implementation.spring location="META-INF/spring/CalculatorService-context.xml"/>
    
    <reference<service name="addServiceStockQuoteService" targetpromote="AddServiceComponentStockQuoteServiceComponent" />
        <reference<interface.java nameinterface="subtractService" target="SubtractServiceComponent" bigbank.stockquote.StockQuoteService"/>
        <binding.ws uri="http://localhost:8081/services/StockQuoteWebService"/>
    </service>

    <reference<component name="multiplyService" target="MultiplyServiceComponent" /StockQuoteServiceComponent">
        <reference<implementation.spring namelocation="divideService" target="DivideServiceComponent" META-INF/spring/StockQuoteService-context.xml"/>
    </component>

</composite>

Declaring Reference

Code Block
<component name="AccountServiceComponent">
    <implementation.spring location="spring-context/Account-spring-context.xml"/>
    
    <reference name="calculatorServicestockQuoteService">
        <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService<binding.ws uri="http://localhost:8081/services/StockQuoteWebService"/>
    </reference>
</component>

See the spring-bigbank-calculator stockquote sample for a complete example of using SCA RMI Web Service binding.

Spring SCA Namespace schema

The spring-sca.xsd can be found at the following location: http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd

Your existing Spring Application context should define the http://www.springframework.org/schema/sca namespace as shown below.

Working with SCA RMI Binding

Declaring Service

Code Block

<composite name="Calculator">
    <service name="CalculatorService" promote="CalculatorServiceComponent">
        <interface.java interface="bigbank.calculator.CalculatorService"/>
        <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
    </service>

    <component name="CalculatorServiceComponent">
Code Block

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <implementation.spring location="META-INF/spring/CalculatorService-context.xml"/>
       xmlns:sca="http://www.springframework.org/schema/sca"
 <reference name="addService" target="AddServiceComponent" />
         xsi:schemaLocation="
<reference name="subtractService" target="SubtractServiceComponent" />
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
<reference name="multiplyService" target="MultiplyServiceComponent" />
        <reference  http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"name="divideService" target="DivideServiceComponent" />
    </component>
</composite>

Declaring Reference

Code Block

<component name="AccountServiceComponent">
    <implementation.spring location="spring-context/Account-spring-context.xml"/>
       
    <sca:service<reference name="StockQuoteServicecalculatorService">
        type="bigbank.stockquote.StockQuoteService" target="StockQuoteServiceBean"/>

    <bean id="StockQuoteServiceBean" class="bigbank.stockquote.StockQuoteImpl"<tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
    </bean>reference>
</beans>
component>

See the spring-bigbank-calculator sample for a complete example of using SCA RMI binding.

Spring SCA Namespace schema

The spring-sca.xsd can be found at the following location: http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsdto make your application context aware of the Spring SCA Namespace.

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.springframework.org/schema/sca"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"
	elementFormDefault="qualified" targetNamespace="http://www.springframework.org/schema/sca">
	<xsd:element name="composite">
		<xsd:complexType>
			<xsd:attribute name="component" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="sca-adapter-class" use="optional">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="reference">
		<xsd:complexType>
			<xsd:attribute name="name" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="type" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="default" use="optional">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="property">
		<xsd:complexType>
			<xsd:attribute name="id" use="optional">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="name" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="type" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="service">
		<xsd:complexType>
			<xsd:attribute name="name" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="type" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="target" use="required">
				<xsd:simpleType><xsd:restriction base="xsd:string" /></xsd:simpleType>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

References

1 SCA Spring Component Implementation Specification - http://www.oasis-opencsa.org/sca-spring
2 Spring Framework - http://static.springframework.org/spring/docs/2.0.x/reference/index.html