spring RMI的使用
Spring整合RMI的原理
客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性。
通过JRMP访问服务。JRMP JRMP:java remote method protocol,Java特有的,基于流的协议。
服务端暴露远程服务
RmiServiceExporter把任何Spring管理的Bean输出成一个RMI服务。通过把Bean包装在一个适配器类中工作。适配器类被绑定到RMI注册表中,并且将请求代理给服务类。
RMI服务端实现类
package com.impl; import com.interfaces.IHelloWord; /**
* Created by lunhui.wei on 2014/11/7.
*/
public class HelloWorld implements IHelloWord{ @Override
public String helloWorld() {
return "Hello World";
} @Override
public String sayHelloToSomeBody(String name) {
return name+" say:"+" Hello world";
}
}
服务端RMI接口类
public interface IHelloWord {
public String helloWorld();
public String sayHelloToSomeBody(String name);
}
服务端运行类
package com; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by lunhui.wei on 2014/11/7.
*/
public class Run {
public static void main(String args[]){
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring-config.xml");
System.out.println("RMI服务伴随Spring的启动而启动了.....");
}
}
服务端spring-config.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloWorld" class="com.impl.HelloWorld"/>
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="helloWorld"/>
<property name="serviceName" value="hello"/>
<property name="serviceInterface" value="com.interfaces.IHelloWord"/>
<property name="registryPort" value="8088"/>
</bean> </beans>
客户端接口类直接使用服务端的接口类直接粘贴过去。
客户端的运行类:
import com.interfaces.IHelloWord;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by lunhui.wei on 2014/11/7.
*/
public class Run {
public static void main(String args[]){
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring-config.xml");
IHelloWord helloWord= (IHelloWord) applicationContext.getBean("helloWorld");
System.out.println(helloWord.helloWorld());
System.out.println(helloWord.sayHelloToSomeBody("zhangsan"));
}
}
客户端Spring 的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloWorld" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://10.61.5.14:8088/hello"/>
<property name="serviceInterface" value="com.interfaces.IHelloWord"/>
</bean>
</beans>
spring RMI的使用的更多相关文章
- Spring RMI (Spring 远程方法调用)
所需jar包...? 不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...
- Spring RMI (Spring 远程方法调用)【原】
所需jar包...? 不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...
- Spring + RMI
服务端: RmiServer.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...
- Spring RMI Example
一: 提供服务的远程一端 1-1. applicationContext.xml <?xml version="1.0" encoding="UTF-8" ...
- Spring Remoting: Remote Method Invocation (RMI)--转
原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp Concept Overview Spring pr ...
- Spring之RMI 远程方法调用 (Remote Method Invocation)
RMI 指的是远程方法调用 (Remote Method Invocation) 1. RMI的原理: RMI系统结构,在客户端和服务器端都有几层结构. 方法调用从客户对象经占位程序(Stub).远程 ...
- Spring之rmi实例演示
环境介绍:本文中服务端客户端使用的都是ssm框架,配置文件分为spring_servlet.xml,spring_service.xml,mybatis.xml 在spring里面使用rmi完成远程调 ...
- spring源码分析之spring-web remoting模块概况及基本概念
spring-web总体分为三部分:caucho.httpinvoker.jaxws,其总体构造图如下: uml结构: 先看看网上搜索到的上述实现的原理吧:Spring RMI,Hessian/Bur ...
- RMI学习
前段时间学习JMX,知道可以使用rmi连接器,就顺便看下rmi是什么东西,RMI 全称Remote Method Invocation-远程方法调用,实现远程对象之间的调用,下面原理图来自网络 服务器 ...
随机推荐
- spark单机模式
1.下载spark,解压2.复制conf/spark-env.sh和conf/log4j.properties cp spark-env.sh.template spark-env.sh cp log ...
- Oracle 数据库排错之 ORA-00600
[错误代码] ORA-00600 [问题描述] ORA-00600: [kcratr1_lastbwr]错误的处理办法 [问题分析] 出现该错误是因为系统强制关机造成的!症状为数据库无法打开! [问题 ...
- 获取jsapi_ticket
String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&a ...
- 集合Map多对多映射(使用xml文件)
我们可以使用set,bag,map等来映射多对多关系.在这里,我们将使用map来进行多对多映射. 在这种情况下,将创建三个表. 多对多映射示例 我们需要创建以下文件来映射map元素.首先创建一个项目: ...
- Package java.sql
Provides the API for accessing and processing data stored in a data source (usually a relational dat ...
- Prime pair connection (Project Euler 134)
题目大意: 对于连续的质数$p1$, $p2$, 满足$5 <= p1 <= 1000000$ 求出最小的整数$S$, 它以 $p1$结尾并且能够被$p2$整除. 求$S$的和. 思路: ...
- Hook length formula 学习笔记 UVALive 6625
最近做到一个关于杨氏矩阵的题目. UVALive 6625 题目大意是用n以内的数填充杨氏矩阵,要求行严格递增,列不严格递增. 求方案数. 数据范围很小,我直接上爆搜,结果TLE了. 后来发现一位学长 ...
- 使用nginx cache缓存网站数据实践
Nginx本身就有缓存功能,能够缓存静态对象,比如图片.CSS.JS等内容直接缓存到本地,下次访问相同对象时,直接从缓存即可,无需访问后端静态服务器以及存储存储服务器,可以替代squid功能. 1 ...
- OpenCV学习笔记七:opencv_nonfree模块
一,简介: 顾名思义,这个模块不是free的.主要包含: 1,SIFT implementation. The class implements SIFT algorithm by D. Lowe. ...
- Android无线测试之—Genymotion模拟器环境搭建
genymotion是一款号称速度最快性能最好的android模拟器,它基于Oracle VM VirtualBox.支持GPS.重力感应.光.温度等诸多传感器:支持OpenGL 3D加速:电池电量模 ...