|Home > Apache Tuscany Docs 2.x > Index > SCA Java Extensions Guide > SCA Java implementation.spring|
|Apache Tuscany Docs 2.x > Index > SCA Java Extensions Guide > SCA Java implementation.spring||Tuscany Home | User List | Dev List | Issue Tracker|
Apache Tuscany Docs 2.x
SCA Java implementation.spring
The Tuscany Java SCA runtime supports components implemented with Spring Framework by using the <implementation.spring> SCDL extension.
The Spring specification 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 specifications document.
In Spring Framework 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.
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.
Tuscany uses Spring Framework 3.0.x-RELEASE (requires Java 1.4+)
The Spring component implementation SCDL has the following format:
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:
b) Specifying a Directory:
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:
Here the target uri specifies the resource as an archive file name "spring.jar", where all the spring related files are available.
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:
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.
Your existing Spring Application context should define the http://www.springframework.org/schema/sca namespace in order to make the Spring aware of the SCA related beans. This is shown below.
Tuscany supports the following configurations to handle multiple Spring Application Context XML files.
Each import element points to an application context xml file.
Each list value points to an application context xml file.
The spring-bigbank sample demonstrates most of the functionality that is specified in the specifications .
See the simple-bigbank-spring sample for a complete example.
See the spring-bigbank-calculator sample for a complete example of using direct SCA references within Spring configuration.
The properties like addService, subtractService, multiplyService and divideService defined in the Spring configuration as shown below
are the direct representation of the SCA references defined in the composite file.
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 properties checkingAccountService, calculatorService and stockQuoteService defined in the Spring configuration as shown below
can be declared explicit as SCA beans in Spring Application Context using the <sca:reference> element.
See the simple-bigbank-spring sample for a complete example of using explicit declaration of SCA related beans.
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.
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.
Declaring Reference in a component which consumes the Service declared above
See the spring-bigbank-stockquote sample for a complete example of using SCA Web Service binding.
See the spring-bigbank-calculator sample for a complete example of using SCA RMI binding.
Tuscany creates an custom Application context with an implementation logic for all SCA related beans like <sca:service>, <sca:reference> and <sca:properties> available in the Spring Application Context.
To access the application context in your application we recommend to use the suggested approach in this article.
Currently Tuscany does not support implicit SCA references and properties for scenario 1 & 2 in spring context as shown below.
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.
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.
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.
Raised as Specification Issue: http://www.osoa.org/jira/browse/JAVA-59
The spring-sca.xsd can be found at the following location: http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd
Spring Framework - http://static.springframework.org/spring/docs/2.5.5/reference/index.html