Spring RMI Example
一: 提供服务的远程一端
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的更多相关文章
- Spring RMI (Spring 远程方法调用)
所需jar包...? 不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...
- Spring RMI (Spring 远程方法调用)【原】
所需jar包...? 不纠结,一股脑儿全导! 源码地址:http://pan.baidu.com/s/1jG8eOmy 先放结构图如下,客户端和服务端都在一个项目中.也可以把服务端的xxx导成j ...
- spring RMI的使用
Spring整合RMI的原理 客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性. 通过JRMP访问服务.JRMP JRMP:ja ...
- Spring + RMI
服务端: RmiServer.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...
- Spring Remoting: Remote Method Invocation (RMI)--转
原文地址:http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp Concept Overview Spring pr ...
- Spring之RMI 远程方法调用 (Remote Method Invocation)
RMI 指的是远程方法调用 (Remote Method Invocation) 1. RMI的原理: RMI系统结构,在客户端和服务器端都有几层结构. 方法调用从客户对象经占位程序(Stub).远程 ...
- Spring之rmi实例演示
环境介绍:本文中服务端客户端使用的都是ssm框架,配置文件分为spring_servlet.xml,spring_service.xml,mybatis.xml 在spring里面使用rmi完成远程调 ...
- spring源码分析之spring-web remoting模块概况及基本概念
spring-web总体分为三部分:caucho.httpinvoker.jaxws,其总体构造图如下: uml结构: 先看看网上搜索到的上述实现的原理吧:Spring RMI,Hessian/Bur ...
- RMI学习
前段时间学习JMX,知道可以使用rmi连接器,就顺便看下rmi是什么东西,RMI 全称Remote Method Invocation-远程方法调用,实现远程对象之间的调用,下面原理图来自网络 服务器 ...
随机推荐
- 15个实用的CSS在线实例教程
前端技术可以说是必须学习的一个技术,现在做网站都需要懂DIV.CSS,在国内很多企业招网页设计师都要求会写基本的前端代码,所以前端技术是 必须了解的,对网页设计师本身也有帮助,今天向大家推荐一些不错的 ...
- 编译升级php之路(5.5.7 到 5.5.37)
为在一台旧服务器上能使用slim,共经历了: 1.安装composer(需要高版本php,原来是5.5.7) 2.升级php版本到5.5.37(编译出错,准备使用docker) 3.升级centos内 ...
- Devexpress treelist 树形控件 实现带三种状态的CheckBox
树形控件是使用频率很高的一种控件.对于属性控件往往需要下面两个功能 1.TreeList带有CheckBox,并且节点要有三种状态(所有的子节点都选中,所有的子节点都没选择,一部分子节点选中).使用 ...
- MyBatis知多少(12)私有数据库
如果你从事软件开发工作有了一段时间的话,那么肯定听过关于“自己动手还是花钱购买” 的争论.该争论是说,针对一个业务问题,我们是应该自己动手构建自己的解决方案呢,还是应 该花钱购买一个声称已经解决了此问 ...
- 一步一步实战扩展 ASP.NET Route,实现小写 URL、个性化 URL
介绍 不知道大家在使用 ASP.NET MVC 时有没有一些扩展要求,反正我是有很多.在使用 MVC 这几年(PS:我是从 1.0 开始学,2.0.3.0 开发至今),我深深地觉得 MVC 的扩展性真 ...
- GNU GCC 扩展属性
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html constructor destructor constructor (prior ...
- 关于Windows Phone平台音乐播放的的技术调研
希望看到这篇文章的开发者能提供你们的想法,让我们一起来探讨一款wp平台上面一款能流畅播放.能流畅拖拽进入条.只发一次请求就可以缓存的最好的播放器.希望大家能对我下面遇到的问题作出回答. 现在出了Win ...
- Asp.net Mvc4 基于Authorize实现的模块权限验证方式
在MVC中,我们可以通过在action或者controller上设置Authorize[Role="xxx"] 的方式来设置用户对action的访问权限.显然,这样并不能满足我们的 ...
- 二叉查找树(一)之 图文解析 和 C语言的实现
概要 本章先对二叉树的相关理论知识进行介绍,然后给出C语言的详细实现.关于二叉树的学习,需要说明的是:它并不难,不仅不难,而且它非常简单.初次接触树的时候,我也觉得它似乎很难:而之所产生这种感觉主要是 ...
- 开放产品开发(OPD):开篇
OPD?这是什么玩意?google一下.忘记说了,最近google被封锁的厉害,那就百度一下吧.可惜,OPD找不出是什么.你今天你找不到是正常的,因为之前还没有OPD,而现在才开始有OPD这个东东.相 ...