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-远程方法调用,实现远程对象之间的调用,下面原理图来自网络 服务器 ...
随机推荐
- 增大VM下linux的根目录空间
增大VM下linux的根目录空间 用的太久,发现VM下的系统空间不足.简单的方法是,分一个新硬盘,挂载到根目录下. 下面是直接增大根目录下空间: 1. 增大vm下的磁盘大小, VM -&g ...
- nginx server_name
在我的机子了nginx的 server_name要配制成127.0.0.1才能用,否则就报错,刚试用nginx还不知道为什么,先记下来
- nn_slow和nn_fast
#define nn_fast(x) __builtin_expect ((x), 1) #define nn_slow(x) __builtin_expect ((x), 0) __builtin_ ...
- java.lang.NullPointerException
你妹的这是什么错误啊? Errors occurred during the build. Errors running builder 'Android Resource Manager' on p ...
- MSIL 教程(二):数组、分支、循环、使用不安全代码和如何调用Win32 API(转)
转自:http://www.cnblogs.com/Yahong111/archive/2007/08/16/857574.html 续上文[翻译]MSIL 教程(一) ,本文继续讲解数组.分支.循环 ...
- js最新手机号码、身份证正则表达式
身份证正则: //身份证正则表达式(15位) isIDCard1=/^[-]\d{}((\d)|([-]))(([||]\d)|[-])\d{}$/; //身份证正则表达式(18位) isIDCard ...
- DevExpress XtraTreeList的复选框 禁用
树的2个事件代码如下,通过节点的tag判断是否禁用节点前的复选框.树的节点加载时设置要禁用的节点tag为-1,不禁用的则设为相关的值 private void treeListPer_CustomDr ...
- PowerShell 启动应用程序【转】
当你在PowerShell中,启动带参数启动可执行应用程序时,可能会碰到参数解析的错误.最好的方式是使用命令 Start-Process,该命令有两个优点: 程序的路径和程序参数分开,可以使用-Fil ...
- win7下IE主页无法修改,IE设置无法保存解决方案
转自:http://www.myhack58.com/Article/48/65/2012/34411.htm 经测,有效! 现象如下: 1.开启后,首先总是指向http://go.microsoft ...
- iOS-图片轮播-SDCycleSCrollView的使用
介绍: SDCycleScrollView 是一款非常强大的轮播图第三方. 轮播流畅,手滑流畅.使用方便.自定义简单. 可以更改pageControl. 一. Demo地址 https://pan.b ...