发表于: 2017-06-20 23:49:20
2 1145
今日完成
1、跑到Tuscany(即意大利的一个地区,大概在地中海上面再往右一点点)的官网发现头上醒目的红字是官方让其retired。。
2、搞完了任务9,没做两个service两个web,过程将和任务8一样,3-6大概说了怎么做
3、过程非常曲折难受,Tuscany的资料太少了,从任务一路做下来,一路资料感觉到789就资料很少了,报错信息拿去搜索极难有答案。
新增代码图:1、先上项目结构图这里插一下maven引入的包
<!-- tuscany SCA相关包 -->
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-base-runtime</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-spring-runtime</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId> org.apache.tuscany.sca</groupId >
<artifactId>tuscany-binding-rmi-runtime</artifactId>
<version> 2.0.1</version>
</dependency>
以及更重要的是官方已经放弃了这个项目,所以2.0.1已经是最高版本,但是也仅仅支持spring3.1以下版本比如这里我用的版本是<spring.version>3.0.5.RELEASE</spring.version>
2、tuscany.composite
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="user-contribution" targetNamespace="http://UserService">
<component name="UserComponent">
<implementation.spring location="spring/spring-service.xml"/>
<service name="UserService" >
<tuscany:binding.rmi uri="rmi://localhost:1199/UserService"/>
</service>
</component>
</composite>
这里需要注意的是implementation.spring不是.java或其他,然后是端口号不能被占用3、spring-service.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sca="http://www.springframework.org/schema/sca"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
<!-- 扫描service包下所有使用注解的类型 因rmi需要指定bean名先弃用
<context:component-scan base-package="cn.yxy.service.impl"/>-->
<bean id="userService" name="userService" class="cn.yxy.service.impl.UserServiceImpl"/>
<!-- tuscany RMI 配置 -->
<sca:service name="UserService" type="cn.yxy.service.UserService" target="userService"/>
<import resource="spring-dao.xml"/>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据库连接池 -->
<property name="dataSource" ref="jdbcDataSource"/>
</bean>
<!-- 配置基于注解的声明式事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
这里需要注意的是,bean userService name值必须指定,而且一定要与下面<sca:里的target一致,以及要import其他所有spring配置文件。还有beans头加上第5行那里,idea会帮你加,eclipse大概不会。4、Userservice接口文件添加注解如下
package cn.yxy.service;
import cn.yxy.domain.User;
import org.oasisopen.sca.annotation.Remotable;
import java.util.List;
@Remotable
public interface UserService {
5、用main函数来启动Tuscany
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import java.util.concurrent.TimeUnit;
public class Tmain {
public static void main(String[] args) throws InterruptedException {
Node node = NodeFactory.newInstance().createNode("tuscany.composite");
System.out.println("111");
node.start();
while (true ) {
TimeUnit.SECONDS.sleep(Long.MAX_VALUE);
}
}
}
这里倒没什么好注意的,注意一下文件名吧,运行结果如下6、我简单的用另一个main函数来调用接口,而且13的代码刚好就是类似任务8中手动获得bean的语句,所以整合将会是简单的,复制一个项目改一下tuscany.composite里的端口号,就可以启动两个service。web端几乎不变,代码在昨天日报我的回复里
studentService1= (StudentService) context.getBean("studentService1");
这行代码改成下面那个lookup就好了
import cn.yxy.service.UserService;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
/**
* Created by Administrator on 2017/6/20.
*/
public class Tcall {
public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
UserService userService = (UserService) Naming.lookup("//localhost:1199/UserService");
System.out.println(userService);
System.out.println(userService.selectByPrimaryKey(8));
}
}
这里也没什么好注意的,lookup的值要与tuscany.composite里rmi监听的一致吧,运行结果如下8、还剩下一个问题,就是打包成war包部署怎么自动调用Tuscany而不是用main函数,不是说main函数就不能用,只是总觉得有点。。尝试在web.xml里加入
<!-- tuscany的过滤器 -->
<filter>
<filter-name>tuscany.wsdl</filter-name>
<filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>tuscany.wsdl</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
无效,部署不报错但如图没有程序在监听1199端口
最后,基本上前面说的每个要注意的地方我都踩坑了,然后一开始不知道用main函数运行,傻傻的在那里一次次打包部署,这个托斯卡纳被官方抛弃,资料又少,故写得详细些,但是目测也没什么人能看到。。。
感谢及参考链接:
某位无名外门师兄日报http://www.jnshu.com/daily/19543?dailyType=others&total=86&page=34&tid=56&oid=5&sort=0&orderBy=3某博客http://blog.csdn.net/solidwang/article/details/17371973吴志勇师兄日报两则
http://www.jnshu.com/daily/24416?dailyType=others&total=91&page=6&uid=9801&sort=0&orderBy=3http://www.jnshu.com/daily/24938?dailyType=others&total=108&page=17&uid=9801&sort=0&orderBy=3
还看了一些其他师兄的日报以及其他乱七八糟的链接就不一一列举了
明日计划
师兄师兄,复盘项目怎么搞?
收获
Tuscany乱七八糟,如其component是其较核心思想,与spring整合时它应如何定义
RMI大概的结构清晰些
##任务8、9的深度思考内容1.什么是rmi?为什么要使用rmi框架?RMI即remote method invocation 远程方法调用,为什么的话个人理解是降低耦合性,部署也会更加灵活,分工明确效率也会提高2.什么是SCA?什么是分布式?分布式有什么优点?Service Component Architecture,简称SCA,也译作服务构件架构 ---wiki分布式系统由独立的服务器通过网络松散耦合组成的。分布式系统可由低价的pc服务器做集群应对高并发访问时的效率比同价的高性能pc高太多,并且很方便随时增加或减少服务器3.为什么要把web和service分离?应用了哪些概念?分离后前后端的专注度就更高了,分工总是利于降低成本和提高效率,应用哪些概念不愿想了。。。总之这是历史的进程!1.什么是微服务?微服务就是做一些微小的工作,微小紧凑的服务,提供一些简明的API供外界调用来实现业务功能,RESTful风格更佳,因为只提供接口,所以进行服务升级也很方便。2.什么是SOA?SOA是面向服务架构,相对于微服务,它提供大而全的一个项目供使用
评论