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

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. varchar和Nvarchar区别

    http://www.cnblogs.com/yelaiju/archive/2010/05/29/1746826.html Unicode字符集就是为了解决字符集这种不兼容的问题而产生的,它所有的字 ...

  2. ural 1071. Nikifor 2

    1071. Nikifor 2 Time limit: 1.0 secondMemory limit: 64 MB Nikifor has a number x. He doesn't need it ...

  3. CF# Educational Codeforces Round 3 E. Minimum spanning tree for each edge

    E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...

  4. 自定义Toast、程序退出时Toast也退出、Toast的用法

    http://blog.csdn.net/wangqilin8888/article/details/7464806 当我们在一个应用中用到Toaster来做为提示时,发现这样一个问题,当某个条件服合 ...

  5. Android HttpURLConnection And HttpClient

    Google的工程师的一个博客写到: HttpURLConnection和HttpClient Volley HTTP请求时:在Android 2.3及以上版本,使用的是HttpURLConnecti ...

  6. Coder-Strike 2014 - Round 1 E. E-mail Addresses

    此题题意就是匹配邮箱,提交时一直在test 14上WA,看了测试用例之后才发现计数用的int溢出,要用long long还是做题经验不够,导致此题未能通过,以后一定要考虑数据量大小 题意是找出邮件地址 ...

  7. Codeforces Round #228 (Div. 2) A. Fox and Number Game

    #include <iostream> #include <algorithm> #include <vector> #include <numeric> ...

  8. Javascript 多浏览器兼容性问题及解决方案

    一.document.formName.item(”itemName”) 问题 问题说明:IE下,可以使用 document.formName.item(”itemName”) 或 document. ...

  9. [转]B树、B-树、B+树、B*树

    题记:转一篇很直观介绍各类B树的文章. B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树, ...

  10. MetaHandler.js:移动端适配各种屏幕

    MetaHandler.js !function () { var opt = function() { var ua = navigator.userAgent, android = ua.matc ...