[color=red]注意:本文基于tuscany-sca-1.6.1进行讲解。(未完待整理) [/color]
在SCA实践-运用tuscany实现SCA(一)中介绍了如何构建SCA应用。
http://maxin001122.iteye.com/blog/907007
本文主要介绍tuscany如何和spring集成。
在 《在SCA实践-运用tuscany实现SCA(一)》介绍了需要的基本数据结构和接口
在和spring集成中,需要修改的代码如下
唯一修改就是去掉了@Reference注解
配置文件修改为如下
新增加spring配置文件
META-INF/spring-context/applicationContext_book.xml
部署文件
<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:sample="http://sample">
<deployable composite="sample:BookSpring"/>
</contribution>
其他代码不变。
在SCA实践-运用tuscany实现SCA(一)中介绍了如何构建SCA应用。
http://maxin001122.iteye.com/blog/907007
本文主要介绍tuscany如何和spring集成。
在 《在SCA实践-运用tuscany实现SCA(一)》介绍了需要的基本数据结构和接口
在和spring集成中,需要修改的代码如下
package org.max.tuscany.demo.service.impl;
import org.max.tuscany.demo.Book;
import org.max.tuscany.demo.service.BookService;
import org.max.tuscany.demo.service.LogService;
import org.max.tuscany.demo.service.SecurityService;
import org.osoa.sca.annotations.Reference;
public class BookServiceImpl implements BookService {
private SecurityService securityService;
private LogService logService;
//@Reference
public void setLogService(LogService logService) {
this.logService = logService;
}
//@Reference
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
@Override
public Book getBook(Long bookId, Long userId) {
System.out.println("BookServiceImpl.getBook is invoked");
if(securityService.securityCheck(userId)){
logService.log("ok");
return new Book(bookId,"tuscany in action");
}else{
logService.log("go back");
}
return null;
}
}
唯一修改就是去掉了@Reference注解
配置文件修改为如下
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
targetNamespace="http://sample" xmlns:sample="http://sample" name="BookSpring">
<service name="BookService" promote="BookServiceComponent">
<interface.java interface="org.max.tuscany.demo.service.BookService" />
<binding.ws />
<tuscany:binding.rmi host="localhost" port="8099"
serviceName="BookService" />
</service>
<component name="BookServiceComponent">
<implementation.spring location="META-INF/spring-context/applicationContext_book.xml"/>
</component>
</composite>
新增加spring配置文件
META-INF/spring-context/applicationContext_book.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">
<!-- The name must equal with service name in *.composite -->
<sca:service name="BookService" type="org.max.tuscany.demo.service.BookService"
target="BookServiceBean" />
<bean id="BookServiceBean" class="org.max.tuscany.demo.service.impl.BookServiceImpl">
<property name="logService" ref="logService" />
<property name="securityService" ref="securityService" />
</bean>
<bean id="logService" class="org.max.tuscany.demo.service.impl.LogServiceImpl"></bean>
<bean id="securityService" class="org.max.tuscany.demo.service.impl.SecurityServiceImpl"></bean>
</beans>
部署文件
<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:sample="http://sample">
<deployable composite="sample:BookSpring"/>
</contribution>
其他代码不变。