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

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. WPF中ControlTemplate和DataTemplate的区别

    下面代码很好的解释了它们之间的区别: <Window x:Class="WPFTestMe.Window12" xmlns="http://schemas.micr ...

  2. iOS学习02C语言分支结构

    1. BOOL类型 返回值:真:YES  假:NO BOOL数据类型占一个字节的内存空间,占位符为%d. 计算机在识别时,YES就替换成1,NO就替换成0. bool是C语言中的布尔类型,返回值为tr ...

  3. ORACLE11g JDBC Driver

    http://blog.163.com/z_rx/blog/static/276363762011312947507/ ORACLE服务器端安装程序找到相应目录"x$\app\Adminis ...

  4. OpenResty 简单编写一个Module

    使用 Lua module 来进行 Lua 代码的复用是推荐的做法.然后在用户代码中直接用require()来调用 module代码: local myTest = {} function myTes ...

  5. topcoder SRM 625 DIV2 AddMultiply

    由于题目告诉肯定至少存在一种解, 故只需要根据条件遍历一下, vector <int> makeExpression(int y) { vector<int> res; ; i ...

  6. 【bzoj2333】 [SCOI2011]棘手的操作 可并堆+lazy标记

    2016-05-31  21:45:41 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2333 (学习了黄学长的代码 有如下操作: U x y ...

  7. Redis_jedis高版本的JedisPoolConfig没有maxActive和maxWait

    dbcp的修改日志显示:change "maxActive" -> "maxTotal" and "maxWait" -> &q ...

  8. C# 窗体位置 Show和ShowDialog(转)

    CenterParent 窗体在其父窗体中居中. CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定. Manual 窗体的位置由 Location 属性确定. Windows ...

  9. 最长递增子序列 O(NlogN)算法

    转自:点击打开链接 最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS. 排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个 ...

  10. [CareerCup] 18.12 Largest Sum Submatrix 和最大的子矩阵

    18.12 Given an NxN matrix of positive and negative integers, write code to find the submatrix with t ...