一: 提供服务的远程一端

1-1. applicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="
  5. http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  7.  
  8. <bean id="userRmiServiceImpl" class="com.goodfan.rmi.service.impl.UserRmiServiceImpl" />
  9. <bean id="userRmi" class="org.springframework.remoting.rmi.RmiServiceExporter">
  10. <property name="service" ref="userRmiServiceImpl" />
  11. <property name="serviceName" value="userRmi" />
  12. <property name="serviceInterface" value="com.goodfan.rmi.service.UserRmiService" />
  13. <property name="registryPort" value="9999" />
  14. </bean>
  15. </beans>

1-2. 接口

  1. package com.goodfan.rmi.service;
  2.  
  3. public interface UserRmiService {
  4. public String sayHello(User user);
  5. }

1-3. javabean

  1. package com.goodfan.rmi.service;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public class User implements Serializable{
  6.  
  7. private static final long serialVersionUID = 8550373205815267923L;
  8. private String userName;
  9.  
  10. public String getUserName() {
  11. return userName;
  12. }
  13.  
  14. public void setUserName(String userName) {
  15. this.userName = userName;
  16. }
  17.  
  18. }

1-4. 实现类

  1. package com.goodfan.rmi.service.impl;
  2.  
  3. import com.goodfan.rmi.service.User;
  4. import com.goodfan.rmi.service.UserRmiService;
  5.  
  6. public class UserRmiServiceImpl implements UserRmiService {
  7.  
  8. @Override
  9. public String sayHello(User user) {
  10. return "Hello, " + user.getUserName();
  11. }
  12.  
  13. }

1-5. ServerTest类

  1. package com.goodfan.rmi.service;
  2.  
  3. import org.springframework.context.support.ClassPathXmlApplicationContext;
  4.  
  5. public class ServerTest {
  6.  
  7. public static void main(String[] args) {
  8. System.setProperty("java.rmi.hostname", "10.7.3.12");
  9. new ClassPathXmlApplicationContext("applicationContext.xml");
  10. System.out.println("server start......");
  11. }
  12. }

二: 本地调用一端

2-1. applicationContext-client

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="
  5. http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  7.  
  8. <bean id="rmiProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
  9. <property name="serviceUrl" value="rmi://10.7.3.12:9999/userRmi"/>
  10. <property name="ServiceInterface" value="com.goodfan.rmi.service.UserRmiService" />
  11. </bean>
  12. </beans> c

2-2. ClientTest类

  1. package com.goodfan.rmi.service;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.support.ClassPathXmlApplicationContext;
  5.  
  6. public class ClientTest {
  7.  
  8. public static void main(String[] args) {
  9. ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-client.xml");
  10. UserRmiService ums = (UserRmiService) ctx.getBean("rmiProxy");
  11. User user = new User();
  12. user.setUserName("RMI");
  13. System.out.println(ums.sayHello(user));
  14. }
  15. }

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. 15个实用的CSS在线实例教程

    前端技术可以说是必须学习的一个技术,现在做网站都需要懂DIV.CSS,在国内很多企业招网页设计师都要求会写基本的前端代码,所以前端技术是 必须了解的,对网页设计师本身也有帮助,今天向大家推荐一些不错的 ...

  2. 编译升级php之路(5.5.7 到 5.5.37)

    为在一台旧服务器上能使用slim,共经历了: 1.安装composer(需要高版本php,原来是5.5.7) 2.升级php版本到5.5.37(编译出错,准备使用docker) 3.升级centos内 ...

  3. Devexpress treelist 树形控件 实现带三种状态的CheckBox

    树形控件是使用频率很高的一种控件.对于属性控件往往需要下面两个功能 1.TreeList带有CheckBox,并且节点要有三种状态(所有的子节点都选中,所有的子节点都没选择,一部分子节点选中).使用 ...

  4. MyBatis知多少(12)私有数据库

    如果你从事软件开发工作有了一段时间的话,那么肯定听过关于“自己动手还是花钱购买” 的争论.该争论是说,针对一个业务问题,我们是应该自己动手构建自己的解决方案呢,还是应 该花钱购买一个声称已经解决了此问 ...

  5. 一步一步实战扩展 ASP.NET Route,实现小写 URL、个性化 URL

    介绍 不知道大家在使用 ASP.NET MVC 时有没有一些扩展要求,反正我是有很多.在使用 MVC 这几年(PS:我是从 1.0 开始学,2.0.3.0 开发至今),我深深地觉得 MVC 的扩展性真 ...

  6. GNU GCC 扩展属性

    http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html constructor destructor constructor (prior ...

  7. 关于Windows Phone平台音乐播放的的技术调研

    希望看到这篇文章的开发者能提供你们的想法,让我们一起来探讨一款wp平台上面一款能流畅播放.能流畅拖拽进入条.只发一次请求就可以缓存的最好的播放器.希望大家能对我下面遇到的问题作出回答. 现在出了Win ...

  8. Asp.net Mvc4 基于Authorize实现的模块权限验证方式

    在MVC中,我们可以通过在action或者controller上设置Authorize[Role="xxx"] 的方式来设置用户对action的访问权限.显然,这样并不能满足我们的 ...

  9. 二叉查找树(一)之 图文解析 和 C语言的实现

    概要 本章先对二叉树的相关理论知识进行介绍,然后给出C语言的详细实现.关于二叉树的学习,需要说明的是:它并不难,不仅不难,而且它非常简单.初次接触树的时候,我也觉得它似乎很难:而之所产生这种感觉主要是 ...

  10. 开放产品开发(OPD):开篇

    OPD?这是什么玩意?google一下.忘记说了,最近google被封锁的厉害,那就百度一下吧.可惜,OPD找不出是什么.你今天你找不到是正常的,因为之前还没有OPD,而现在才开始有OPD这个东东.相 ...