一: 提供服务的远程一端

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. 学习之路三十八:Hook(钩子)的学习

    好久没写文章了,还记得年前面试了一家公司,为了检测一下我的学习能力,给了我一个任务,做一个自动登录并自动操作菜单的程序. 花了几天的时间研究了Hook以及使用WindowsAPI操作程序的知识,现在记 ...

  2. kwm备忘

    brew install homebrew/binary/kwm ==> Tapping homebrew/binary Cloning into '/usr/local/Library/Tap ...

  3. 没有 RunInstallerAttribute.Yes 的公共安装程序。在 C:/Program/xx.exe 程序集中可能可以找到

    今天在装服务的时候,装了半天总是提示 没有 RunInstallerAttribute.Yes 的公共安装程序.在 C:/Program/xx.exe 程序集中可能可以找到“Yes”属性. 才发现同事 ...

  4. 在线读取office 文件(Word excel 等)

    https://view.officeapps.live.com/op/view.aspx?src=http://www.xxx.com/uploadfile/app/11.xls src 后面的网址 ...

  5. Ubuntu12.04 安装PyCharm

    1. 下载 选择Linux Tab,选择下载免费的Community Edition[1].当前版本是3.4 2. 安装PyCharm 按照官网给出的安装指导[2]进行安装. (1) Copy the ...

  6. Js 一些方法(一)

    (function ($) { var promoter = promoter || {}; promoter.utils = (function () { var controller = &quo ...

  7. {转}Unity3d+Jenkins 自动编译iOS、Android版本(U3D远程自动打包工具)

    http://www.cnblogs.com/yinghuochong/archive/2013/09/01/3294940.html

  8. Unity3d导出Android的apk文件时相关问题的解决办法

    今天上午着手将一个unity3d开发的小游戏build到android手机上运行,结果遇到了不少问题. 首先遇到的第一个问题是在build到一半的时候,弹出如下报错: Error building P ...

  9. netty ByteBuf分析

    1.Heap Buffer(堆缓冲区) 2.Direct Buffer(直接缓冲区) 3.Composite Buffer(复合缓冲区) 4.PooledByteBuf 池缓冲 readerInex ...

  10. AndroidUI优化工具——HierarchyViewer

    先说些题外话,希望路过的各位支持,博主有幸成为2013年度博客之星的候选人,期待你的一票,谢谢. 投票猛击: http://vote.blog.csdn.net/blogstaritem/blogst ...