WEB开发网
开发学院软件开发Java 使用 Spring Framework 设计和开发 SCA 组件,第 ... 阅读

使用 Spring Framework 设计和开发 SCA 组件,第 1 部分: 三剑客:Spring、SCA 和 Apache Tuscany

 2009-11-23 00:00:00 来源:WEB开发网   
核心提示: calculator.composite 使用 <reference> 元素定义 CalculatorComponent 与其他四个服务之间的依赖关系,比如说 AddComponent、SubtractComponent、MultiplyComponent 和 DivideCompo

calculator.composite 使用 <reference> 元素定义 CalculatorComponent 与其他四个服务之间的依赖关系,比如说 AddComponent、SubtractComponent、MultiplyComponent 和 DivideComponent。它们是使用不同技术实现的。AddComponent 提供 addService 实现,用于返回两数之和。同样,SubtractComponent 提供 subtractService 实现,用于返回两数之差。MultiplyComponent 提供 multiplyService 实现,用于返回两数之积。DivideComponent 则提供 divideService 实现。

您可能注意到在 calculator.composite 中,AddComponent、SubtractComponent、MultiplyComponent 和 DivideComponent 并未使用 <service> 元素明确公开任何服务(采用这种方式,本示例声明为 CalculatorComponent 公开了 CalculatorService)。这样,当您的 SCA 组件未使用 <service> 元素明确公开任何服务时,则 SCA 运行时默认会使用 binding.sca 绑定公开您的组件。同样,在 CalculatorComponent 中,您不必为这些组件引用指定任何具体的绑定信息。SCA 运行时提供了默认的 binding.sca 绑定,用于关联各组件。有关 binding.sca 的详细信息,请参阅 SCA Assembly Model Specification。

在本例中,CalculatorComponent 是一个 Spring 应用程序,它使用 Spring beans 定义了业务逻辑。在您的 Spring 应用程序上下文定义文件中声明所需的 SCA 依赖关系非常重要。

创建一个名称为 calculator-context.xml 的 Spring 应用程序上下文定义文件。如清单 3 所示,通过声明实现所需功能需要的 beans 以及它们的依赖关系,提供了 CalculatorComponent 的业务逻辑。

清单 3. calculator-context.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=" 
 http://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 id="Calculator" class="calculator.CalculatorServiceImpl">     
    <property name="add" ref="addService"/> 
    <property name="subtract" ref="subtractService"/> 
    <property name="multiply" ref="multiplyService"/> 
    <property name="divide" ref="divideService"/> 
  </bean> 
 
</beans> 

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:使用 Spring Framework

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接