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. tomcat遇到版本问题

    1.Dynamic web module 2.J2EE  Web modules 3.Tomcat version 4.<web-app xmlns:xsi="http://www.w ...

  2. 【原创】菜鸟版Android 笔记2- Activity

    1. Activity介绍 Acitivity在安卓开发中非常重要,他很像Java桌面开发中的JFrame,在MVC模式中属于Controller,一般一个应用程序通常由多个松耦合关系的activit ...

  3. IOS项目开发中的文件和文件夹操作

    + (NSFileManager *)getNSFileManager { // iNSFileManager是一个静态变量 if (!iNSFileManager) { iNSFileManager ...

  4. java算法学习

    最大公约数 欧几里得算法 描述:计算两个非负整数p和q的最大公约数: 若q是0,则最大公约数为p. 否则,将p除以q得到余数r,p和q的最大公约数即为q和r的最大公约数. 根据算法的自然描述,我们可以 ...

  5. Java基础 - 强引用、弱引用、软引用、虚引用

    1.强引用(StrongReference) 强引用是使用最普遍的引用. 假设一个对象具有强引用.那垃圾回收器绝不会回收它.例如以下: [java] view plaincopyprint" ...

  6. 通过ssh隧道访问mysql(转载)

    我的机器可以连接服务器A,A可以访问服务器B上的mysql,但是我的机器不能访问B,所以我需要建立一个我本地机器到服务器A的ssh隧道来访问服务器B上的mysql. 理一下思路: 1.我要ssh的服务 ...

  7. 补装老版本的Java SE

    到oracle注册账号下载bin文件 在bin文件下载目录打开终端复制下面到命令 # chmod +x jdk-6u21-linux-i586.bin 注意版本不同,比如我这次下载到是6u45 chm ...

  8. 从头认识java-13.9 隐式和显示的创建类型实例

    对于上一章节擦除引起的问题与解决的方法有读者提出过于简单.这里解释一下:由于笔者本身也遇不到对应的问题.仅仅是凭空想像一些有可能的问题,基于水平有限,因此上一章节写的比較简单,欢迎广大读者踊跃提意见, ...

  9. HDU3062-Party(2-SAT)

    pid=3062">题目链接 思路:2-SAT的模版题 代码: #include <iostream> #include <cstdio> #include & ...

  10. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.6——签署发布apk

    问题: 为了将APK发布到google市场,需要对APK数字签名. 解决方案: 可以使用java的keytoll命令去创建一个证书,并且在gradle配置文件的signingConfigs块使用. 讨 ...