一: 提供服务的远程一端

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. VS2013 解决方案文件结构分析

    http://www.cnblogs.com/haogj/p/4248030.html Visual Studio 的解决方案文件是一个文本文件,其中的内容不是太复杂,有些时候 Visual Stud ...

  2. Populating Next Right Pointers in Each Node II--leetcode难题讲解系列

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  3. Tomcat Manager 用户名和密码配置

    在Tomcat中,应用程序的部署很简单,只需将你的WAR放到Tomcat的webapp目录下,Tomcat会自动检测到这个文件,并将其解压.在浏览器中访问这个应用的Jsp时,通常第一次会很慢,因为To ...

  4. 【原】Linux Raid 实验

    本文参照以下两个链接,将实验重做了一遍,目的就是加深印象及提升实操能力 参照链接:http://www.opsers.org/base/learning-linux-the-day-that-the- ...

  5. SNF开发平台WinForm之三-开发-单表选择控件创建-SNF快速开发平台3.3-Spring.Net.Framework

    3.1运行效果: 3.2开发实现: 3.2.1 这个开发与第一个开发操作步骤是一致的,不同之处就是在生成完代码之后,留下如下圈红程序,其它删除. 第一个开发地址:开发-单表表格编辑管理页面 http: ...

  6. 在线头像上传(js)

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. ubuntu remove mysql

    ubuntu 彻底删除 mysql 然后重装 mysql 删除 mysql sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get r ...

  8. 关于js中的几个小问题。

    问题1: 使用连续赋值后面的变量会成为全局对象的一个属性,并且这个属性可以通过delete删除. 原因:赋值语句是从右往左执行的,我们将10赋值给了c,但是c此时还声明,接着把c的返回值赋值给了b,但 ...

  9. Spring Remoting: Hessian--转

    原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-hessian.jsp Concept Overview The p ...

  10. sqlserver查找表在哪个数据库脚本

    EXEC sp_MSforeachdb @command1='IF object_id(''?'' + ''..table_name'') IS NOT NULL PRINT ''?'''