SCA views Spring as a natural partner which can be used as a component implementation technology. The Spring framework can be used to create components and wire them within a module using its dependency injection capabilities. SCA may be used to extend the capabilities of Spring components by publishing Spring beans as entry points to be accessed as services by other modules as well as by providing Spring beans with service references wired to services of other modules.
Spring Framework是构建Java应用的一个流行平台,您可以通过developerWorks的文章"Spring 系列: Spring 框架简介"来了解Spring框架。Spring提供了IoC容器,一般采用表1中第二种通过JavaBeans的setter方式实现依赖注入。通过在Spring配置文件ApplicationContext.xml中描述bean的信息,Spring IoC将根据这个文件在容器中实例化bean,再通过BeanFactory(在org.springframework.beans.facotry包中)找到实例化的bean。
在两个Module中的Component进行通信时需要将一个component导出,然后另一个component再导入。在导出导入时可以选择SCA binding也可以选择Web service binding,具体选择哪种方式要根据具体环境而定。如果两个模块在一个subsystem中(或者说在同一个应用服务器上)可以直接选择SCA binding;相反则要选择web service binding,通过WSDL进行调用交互。通过WSDL调用的方式与引用外部service一样,不再详细介绍,下面主要介绍如何通过SCA binding的方式进行跨module的component之间的调用。
清单8 QueryBalance.java in SimpleBankWebClient project.
InitialContext ic = new InitialContext();
Service service = (Service) ic.lookup("java:comp/env/service/SimpleBankFacadeExport_
SimpleBankFacadeHttpService");
SimpleBankFacade simpleBankFacade =
(SimpleBankFacade)service.getPort(SimpleBankFacade.class);
FacadeOutput output = simpleBankFacade.queryBalance(customerID,
password);
Service Integration Bus在WebSphere Application Server中,是早期IBM实现ESB产品,现在虽然可以作为一种开发策略,但已不推荐使用,推荐使用WESB提供的ESB服务。可参照IBM WebSphere 开发者技术期刊: 使用 WebSphere Application Server V6 构建企业服务总线 -- 第二部分来了解Sibus。
WESB(WebSphere Enterprise Service Bus)为构建在开放标准和SOA的IT环境提供了一个ESB,相对Sibus来说它使构建中间层更简单,更容易管理,可以在前期开发中介功能,提供更广泛的连接。WID为WESB提供了一个很好的开发工具,通过构建Mediation module来提供ESB服务,如下图WESB的中介模型图。