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的使用的更多相关文章

  1. Spring RMI (Spring 远程方法调用)

    所需jar包...?    不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...

  2. Spring RMI (Spring 远程方法调用)【原】

    所需jar包...?    不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...

  3. Spring + RMI

    服务端: RmiServer.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...

  4. Spring RMI Example

    一: 提供服务的远程一端 1-1. applicationContext.xml <?xml version="1.0" encoding="UTF-8" ...

  5. Spring Remoting: Remote Method Invocation (RMI)--转

    原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp Concept Overview Spring pr ...

  6. Spring之RMI 远程方法调用 (Remote Method Invocation)

    RMI 指的是远程方法调用 (Remote Method Invocation) 1. RMI的原理: RMI系统结构,在客户端和服务器端都有几层结构. 方法调用从客户对象经占位程序(Stub).远程 ...

  7. Spring之rmi实例演示

    环境介绍:本文中服务端客户端使用的都是ssm框架,配置文件分为spring_servlet.xml,spring_service.xml,mybatis.xml 在spring里面使用rmi完成远程调 ...

  8. spring源码分析之spring-web remoting模块概况及基本概念

    spring-web总体分为三部分:caucho.httpinvoker.jaxws,其总体构造图如下: uml结构: 先看看网上搜索到的上述实现的原理吧:Spring RMI,Hessian/Bur ...

  9. RMI学习

    前段时间学习JMX,知道可以使用rmi连接器,就顺便看下rmi是什么东西,RMI 全称Remote Method Invocation-远程方法调用,实现远程对象之间的调用,下面原理图来自网络 服务器 ...

随机推荐

  1. linux 一行一行的读取文件

    #!/bin/bash #reading data from a file count= cat test1 | while read line do echo "Line $count: ...

  2. 如何实现uboot和linux之间的参数传递

    参考http://cgxcn.blog.163.com/blog/static/132312422009101133251202/ 参考:http://blog.chinaunix.net/uid-1 ...

  3. TPM概述

    TPM(Trusted Platform Module)安全芯片,是指符合TPM(可信赖平台模块)标准的安全芯片.标准由TCG(可信赖计算组织,Trusted Computing Group)提出,目 ...

  4. 大端BigEndian、小端LittleEndian与字符集编码

    BigEndian(大端):低字节在高内存地址 LittleEndian(小端):低字节在低内存地址 也就是看低字节在高内存地址还是低内存地址,也就是看低字节在前还是高字节在前,低字节在前自然是小端, ...

  5. 切比雪夫多项式(Chebyshev Polynomials)

    切比雪夫多项式在逼近理论中有重要的应用.这是因为第一类切比雪夫多项式的根(被称为切比雪夫节点)可以用于多项式插值.相应的插值多项式能最大限度地降低龙格现象,并且提供多项式在连续函数的最佳一致逼近. 参 ...

  6. 通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML。

    通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML. JavaScript 能够改变页面中的所有 HTML 元素 JavaScript 能够改变页面中的所有 HTML ...

  7. Large repunit factors (Project Euler 132)

    题目大意: 求出 大数111111.....1 (1e9个1)  前40个质因子的和. 思路:可以把原来的数表示成$\frac{10^k - 1}{9}$ 其中$k=10^9$ 如果一个质数$p$ 满 ...

  8. gitlab报错收集

    登录502报错 一般是权限问题,解决方法: /var/log/gitlab 如果还不行,请检查你的内存,安装使用GitLab需要至少4GB可用内存(RAM + Swap)! 由于操作系统和其他正在运行 ...

  9. python中json操作

    1.写操作.json文件dumps().dump()函数 d = { 'zll': { 'addr': '北京', 'age': 28 }, 'ljj': { 'addr': '北京', 'age': ...

  10. 【BZOJ2870】最长道路tree 点分治+树状数组

    [BZOJ2870]最长道路tree Description H城很大,有N个路口(从1到N编号),路口之间有N-1边,使得任意两个路口都能互相到达,这些道路的长度我们视作一样.每个路口都有很多车辆来 ...