Designing and developing SCA components using the Spring Framework, part 2nd

Source: Internet
Author: User
Tags constructor sca xmlns

Designing and developing SCA components using the Spring Framework, part 2nd-Advanced techniques for using Apache Tuscany

Brief introduction

This series uses the Spring Framework to design and develop SCA components, part 1th: The Three Musketeers: Spring, SCA, and Apache Tuscany outlines the benefits of integrated use of SCA and spring. You learned how to expose the spring bean as an SCA service and how to access SCA services and properties within a spring application.

This article explores some of the advanced features of the Apache Tuscany Runtime support. Learn how to synthesize multiple application contexts as an implementation of an SCA component. SCA annotations can be used to explicitly declare SCA services, references, and properties within the Spring Bean class. Download the source code for the calculator sample.

The examples in this article use the Apache Tuscany SCA Java™ Technology Runtime V1.5.1. To run this sample application, you need to download the binary release of the Apache Tuscany SCA Java implementation.

Use multiple application contexts for SCA components

In the design and development of SCA components using the Spring Framework, part 1th: The Musketeers: Spring, SCA, and Apache Tuscany, you learned that a spring application can be defined as a SC within an SCA composite set (i.e. SCDL) A component, which is formatted as shown in Listing 1.

Listing 1. SCA Composite set with a Spring component

<composite  xmlns="http://www.osoa.org/xmlns/sca/1.0" 
    xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" 
    targetNamespace="http://calc" 
   xmlns:c="http://calc" 
   name="Calculator"> 
 
  <component  name="CalculatorServiceComponent"> 
        <implementation.spring location="targetURI"/> 
   </component> 
 
</composite> 

The Location property of the <implementation.spring> element specifies the target URI to point to an archive (JAR), a directory, or directly to a spring application context file. In any case, when using the Location property of the <implementation.spring> component, Apache Tuscany only allows one application context as the target application context as the implementation of the SCA component.

The Apache Tuscany allows SCA components to be implemented using a variety of application contexts, based on the target application context (identified by the <implementation.spring> element's Location attribute in this SCA compound set file) A classpathxmlapplicationcontext (as shown in Listing 3) for the bean. Listing 2 shows an example.

Listing 2. SCA Composite set with a Spring component

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
    xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
    targetNamespace="http://calc"
    xmlns:c="http://calc"
    name="Calculator">

   <component name="CalculatorServiceComponent">
        <implementation.spring location="beanRefContext.xml"/>
   </component>
</composite>

Listing 3. Beanrefcontext.xml

<beans xmlns= "Http://www.springframework.org/schema/beans"
xmlns:xsi= http://www.w3.org/2001/ Xmlschema-instance "
xmlns:sca=" Http://www.springframework.org/schema/sca "
xsi:schemalocation="
H      Ttp://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd
    Http://www.springframework.org/schema/sca
Http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd

<bean class= "Org.springframework.context.support.ClassPathXmlApplicationContext"
<constructor-arg
<list>
<value>context1.xml</value>
<value>       Context2.xml</value>
<value>context3.xml</value>
</list>
</constructor-arg>
</bean>
</beans>

The intent of this Apache Tuscany runtime is to treat all target application contexts that have a bean definition (classpathxmlapplicationcontext as a Bean Class) as a scenario with multiple application contexts. This Tuscany will then create a combined application context instance for the column application context file identified by the Classpathxmlapplicationcontext Bean's constructor parameter.

In the example in Listing 2, the target application context that is defined as an implementation of Calculatorservicecomponent is beanrefcontext.xml. In a typical scenario (in a single application context scenario), the Tuscany runtime creates an application context instance for Beanrefcontext.xml and uses it as an implementation instance of Calculatorservicecomponent.

In Listing 3, Beanrefcontext.xml defines only one bean definition (classpathxmlapplicationcontext as the Bean Class). This scenario is seen by the Tuscany runtime as a scenario that contains a variety of application contexts. This column of application context files (Context1.xml, Context2.xml, and Context3.xml) identified by the constructor parameter defined by the Classpathxmlapplicationcontext bean are synthesized To create an instance of an application context to act as an implementation instance of Calculatorservicecomponent. Figure 1 shows an example.

For a scenario that contains multiple contexts, each application context file identified by the constructor parameter defined by the Classpathxmlapplicationcontext bean can have its own SCA service, References and attributes (declared in an explicit or implicit manner).

Figure 1. SCA Runtime with Classpathxmlapplicationcontext

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.