发表于: 2019-05-28 22:27:48
1 574
今天完成的事情:
完成了spring+Tuscany的demo
spring+Tuscany是让spring来管理接口,Tuscany来调用spring的方法来暴露接口
接口和实现类文件和之前的不变
加入spring依赖
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-spring-runtime</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
Tuscany最高只支持spring3.05版本
1.新建spring配置文件calculator-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--注解注入-->
<context:component-scan base-package="service"/>
<!--手动注入-->
<!--<bean name="addService" class="service.impl.AddInterfaceImpl"/>-->
<!--<bean name="subtractService" class="service.impl.SubtractInterfaceImpl"/>-->
<!--<bean name="multiplyService" class="service.impl.MultiplyInterfaceImpl"/>-->
<!--<bean name="divideService" class="service.impl.DivideInterfaceImpl"/>-->
<sca:service name="Calculator" type="service.CalculatorInterface" target="calculator"/>
<!--手动注入-->
<!--<bean id="Calculator" class="service.impl.Calculator" name="calculator">-->
<!--<property name="add" ref="addService"/>-->
<!--<property name="subtract" ref="subtractService"/>-->
<!--<property name="multiply" ref="multiplyService"/>-->
<!--<property name="divide" ref="divideService"/>-->
<!--</bean>-->
<sca:reference name="add" type="service.AddInterface"/>
<sca:reference name="subtract" type="service.SubtractInterface"/>
<sca:reference name="multiply" type="service.MultiplyInterface"/>
<sca:reference name="divide" type="service.DivideInterface"/></beans>
2.修改Calculator.composite中的实现方式为spring的方法
<implementation.spring location="calculator-context.xml"/>
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
name="Calculator" targetNamespace="http://com.jnshu"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1">
<!--组合构件-->
<component name="CalculatorServiceComponent">
<!--实现-->
<implementation.spring location="calculator-context.xml"/>
<!--<implementation.java class="service.impl.Calculator"/>-->
<!--暴露服务-->
<service name="Calculator">
<interface.java interface="service.CalculatorInterface"/>
<tuscany:binding.rmi uri="rmi://127.0.0.1:8090/CalculatorRMI"/>
</service>
<!--引用-->
<reference name="add" target="AddComponent"/>
<reference name="subtract" target="SubtractComponent"/>
<reference name="multiply" target="MultiplyComponent"/>
<reference name="divide" target="DivideComponent"/>
</component>
<!--构件 组合构件中引用的实现-->
<component name="AddComponent">
<implementation.java class="service.impl.AddInterfaceImpl"/>
</component>
<component name="SubtractComponent">
<implementation.java class="service.impl.SubtractInterfaceImpl"/>
</component>
<component name="MultiplyComponent">
<implementation.java class="service.impl.MultiplyInterfaceImpl"/>
</component>
<component name="DivideComponent">
<implementation.java class="service.impl.DivideInterfaceImpl"/>
</component>
</composite>
明天计划的事情:
开始复习,学习redis集群
遇到的问题:
整合进项目的时候出现很多问题,一个是service名字重复,无法组合构件,暴露多个接口一直报错找不到引用,修改了各个接口的方法名后用组合构件的方法暴露,redis出现版本问题,jedis的包下载1.0.0的版本。redis-spring的包最低1.3.0的仓库资源可能有问题下载半个小时也没下来。删光redis的代码,运行出现了报错
Business interface dao.JobMapper is not compatible with service.JobService感觉也是jar包版本问题
收获:
Tuscany版本太老了,和现在用的很多jar包版本不兼容。
评论