一、定义远程服务器上接口

public interface RMIService {

public String getInfo(); }

二、实现远程服务器上接口

public class RMIServiceImpl implements RMIService{

public String getInfo() { String msg = "RMI 服务!"; return msg; }

}

三、配置服务器文件 applicationContext_service.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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default- default-lazy-init="false"> <!-- 用户RMI接口实现类 --> <bean name="RMIServer" class="com.rim.test.RMIServiceImpl"/> <!-- 暴露RMI服务配置 --> <bean name="rimServiceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="service" ref="RMIServer"/> <!-- 暴露给客户调用服务 --> <property name="serviceName" value="TestService"/> <!-- 调用接口 --> <property name="serviceInterface" value="com.rim.test.RMIService"/> <property name="registryPort" value="1099"/> </bean> </beans> 四、启动服务器

import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ServiceMainTest {

public static void main(String[] args) { ApplicationContext appContext=new ClassPathXmlApplicationContext("applicationContext_service.xml"); appContext.getBean("rimServiceExporter");

} }

五、配置客户端文件 applicationContext_client.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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default- default-lazy-init="true"> <!-- 客户端调用RMI服务配置 --> <bean name="RMIServiceImpl" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://192.168.1.179:1099/TestService"/> <property name="serviceInterface" value="com.rim.test.RMIService"/> </bean> </beans>

六、客户端获取远程接口上的数据

import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ClientMainTest {

public static void main(String[] args) { ApplicationContext appContext1=new ClassPathXmlApplicationContext("applicationContext_client.xml"); RMIService rmi = (RMIService)appContext1.getBean("RMIServiceImpl"); System.out.println(rmi.getInfo()); }

}

Spring的RMI远程调用 - (示例)的更多相关文章

  1. Spring 配置RMI远程调用

    项目中遇到了跨系统调用,当初想的是用webservice或者是hessian.但是这个接口用到的并不多,而且是一个非常简单的方法.所有便想到了RMI.在spring中 实现RMI非常简单. 暴露服务: ...

  2. java RMI 远程调用

    1.背景 在学习代理模式的过程中接触到了远程调用,jdk有自己的RMI实现,所以这边自己实现了RMI远程调用,并记录下心得. 感受最深的是RMI和现在的微服务有点相似,都是通过"注册中心&q ...

  3. WebService与RMI(远程调用方式实现系统间通信)

    前言 本文是<分布式java应用基础与实践>读书笔记:另外参考了此博客,感觉讲的挺好的,尤其是其中如下内容: 另外,消息方式实现系统间通信本文不涉及.RMI则只采用spring RMI框架 ...

  4. (转载)spring 之间的远程调用-Spring Http调用的实现

    原文:https://www.cnblogs.com/lewisat/p/6132082.html 1:Spring Http设计思想 最近在研究公司自己的一套rpc远程调用框架,看到其内部实现的设计 ...

  5. cas的http配置和rmi远程调用

    1.cas配置http请求(服务端) 1) 解压cas-server-3.4.4-release.zip将modules目录下的cas-server-webapp-3.4.4.war改名称为cas.w ...

  6. hession RMI 远程调用

    /** * * @author administror * 在java中,需要去extends 继承java.rmi.Remote 接口,才能称为在于服务器流的远程对象. * 各客服端调用 * */p ...

  7. java项目中rmi远程调用实例

    1.创建一个学生实体类Student.java: package com.RMIdemo.entity; @SuppressWarnings("serial") public cl ...

  8. Spring @Async实现异步调用示例

    什么是“异步调用”? “异步调用”对应的是“同步调用”,同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执行:异步调用指程序在顺序执行时,不等待异步调用的语句返回结果 ...

  9. Java中RMI远程调用demo

    Java远程方法调用,即Java RMI(Java Remote Method Invocation),一种用于实现远程过程调用的应用程序编程接口.它使客户机上运行的程序可以调用远程服务器上的对象.远 ...

随机推荐

  1. Python: 常用list, string处理功能

    #1. keep strings in double quote as one word when split string to words #e.g. str = ‘a b "is si ...

  2. linux中用shell获取时间,日期

    linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...

  3. [转]Mac 科研常用软件

    转自:http://bbs.feng.com/read-htm-tid-7698336.html 我的 Mac 是 2012 年的 Pro Retina,现在主要用的是 Mac 系统,Windows ...

  4. 使用 Git 和 Visual Studio Online 进行版本控制

    参考资料: 在开发计算机上设置 Git(配置.创建.克隆.添加) 关于 Git 和 Visual Studio Online 是什么请自行百度 转载请注明来源: http://www.cnblogs. ...

  5. [深入浅出WP8.1(Runtime)]Toast通知

    9.1 Toast通知 Toast通知是在屏幕最顶上弹出来的临时通知,是Windows Phone通用的弹出式短暂的通知,默认的系统消息都是采用Toast通知的形式,比如当你手机收到短信的时候,在手机 ...

  6. Find和FirstOrDefault()有什么区别?

    Find方法和FirstOrDefault方法效果相同,都是返回满足条件的第一个元素,如果没有该元素,则返回null. 那么这两个扩展方法有什么不同? 1)Find方法是.netFramework2. ...

  7. BZOJ4542: [Hnoi2016]大数

    Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小B还有一个素数P.现在,小 B 提出了 M 个询问,每个 ...

  8. Background agent

    Periodic Task Periodic agents run for a small amount of time on a regular recurring interval. Typica ...

  9. 黑马程序员----java基础笔记中(毕向东)

    <p>------<a href="http://www.itheima.com" target="blank">Java培训.Andr ...

  10. css中margin-left与left的区别

    研究下拉菜单和弹出菜单时比较所得: 1.直接在css中设置left生效的前提是必须设置父容器position:absolute或relative,如果不设置则会显示为最近一个定位的父对象左边相关的位置 ...