一: 提供服务的远程一端

1-1. applicationContext.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-3.0.xsd"> <bean id="userRmiServiceImpl" class="com.goodfan.rmi.service.impl.UserRmiServiceImpl" />
<bean id="userRmi" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="userRmiServiceImpl" />
<property name="serviceName" value="userRmi" />
<property name="serviceInterface" value="com.goodfan.rmi.service.UserRmiService" />
<property name="registryPort" value="9999" />
</bean>
</beans>

1-2. 接口

package com.goodfan.rmi.service;

public interface UserRmiService {
public String sayHello(User user);
}

1-3. javabean

package com.goodfan.rmi.service;

import java.io.Serializable;  

public class User implements Serializable{  

    private static final long serialVersionUID = 8550373205815267923L;
private String userName; public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} }

1-4. 实现类

package com.goodfan.rmi.service.impl;

import com.goodfan.rmi.service.User;
import com.goodfan.rmi.service.UserRmiService; public class UserRmiServiceImpl implements UserRmiService { @Override
public String sayHello(User user) {
return "Hello, " + user.getUserName();
} }

1-5. ServerTest类

package com.goodfan.rmi.service;

import org.springframework.context.support.ClassPathXmlApplicationContext;  

public class ServerTest {  

    public static void main(String[] args) {
System.setProperty("java.rmi.hostname", "10.7.3.12");
new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("server start......");
}
}

二: 本地调用一端

2-1. applicationContext-client

<?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-3.0.xsd"> <bean id="rmiProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://10.7.3.12:9999/userRmi"/>
<property name="ServiceInterface" value="com.goodfan.rmi.service.UserRmiService" />
</bean>
</beans> c

2-2. ClientTest类

package com.goodfan.rmi.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class ClientTest { public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-client.xml");
UserRmiService ums = (UserRmiService) ctx.getBean("rmiProxy");
User user = new User();
user.setUserName("RMI");
System.out.println(ums.sayHello(user));
}
}

Spring RMI Example的更多相关文章

  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的使用

    Spring整合RMI的原理 客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性. 通过JRMP访问服务.JRMP JRMP:ja ...

  4. Spring + RMI

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

  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. 初探Stage3D(三) 深入研究透视投影矩阵

    关于本文 本文主要讲解从数学的角度如何推导出Stage3D中用到的两个投影矩阵 perspectiveLH public function perspectiveLH(width:Number,hei ...

  2. 兼容IE与firefox的css 线性渐变(linear-gradient)

    IE系列 filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900 ...

  3. asp.net mvc 配合前端js的CMD模块化部署思想,小思路

    1)布局视图,用于协调普通视图和共享视图,实现js库自由选择引用 @{ //具体页面定义好需要引入的js文件,在这里通过共享视图渲染出来 var jsDefines = ViewBag.JsDefin ...

  4. 使用 crosswalk-cordova 打包sencha touch 项目,再也不用担心安卓兼容问题!

    国内的安卓手机品牌众多,安卓操作系统碎片化也很严重,我们使用sencha touch 开发的应用不可避免的出现了各种无解的兼容性问题. 有时候我就在想,有没有既能支持cordova,又能让我们把Chr ...

  5. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  6. Eclipse 常用最新插件.标记

    Properties Editor     编辑java的属性文件,并可以自动存盘为Unicode格式 http://marketplace.eclipse.org/content/propertie ...

  7. QCopChannel的用法

    QT提供了很多的进程间通讯的方法,例如共享内存,QProcess等等.但有一种方法是嵌入式端所独有的,那就是Qt Communications Protocol(QCOP)QT通讯协议,这种方法只能用 ...

  8. VB6.0手册

    1.Form窗体事件 Private Sub Form_Activate() '焦点在此窗口时触发  MsgBox "窗体的Activate事件"  End Sub    Priv ...

  9. 【转载】如何在Ubuntu上安装LAMP服务器系统?

    转载自:http://os.51cto.com/art/201307/405333.htm [2013年7月25日 51CTO外电头条]为何应该在Ubuntu上安装LAMP服务器?从事Web开发工作时 ...

  10. Gulp.js - 简单、直观的自动化项目构建工具

    Gulp.js 是一个简单.直观的构建系统.崇尚代码优于配置,使复杂的任务更好管理.通过结合 NodeJS 的数据流的能力,你能够快速构建.通过简单的 API 接口,只需几步就能搭建起自己的自动化项目 ...