Spring整合 RMI
来源:互联网 发布:章泽天 清华 知乎 编辑:程序博客网 时间:2024/05/03 18:59
Spring整合RMI的原理
客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性。
通过JRMP访问服务。JRMP JRMP:java remote method protocol,Java特有的,基于流的协议。
服务端暴露远程服务
RmiServiceExporter把任何Spring管理的Bean输出成一个RMI服务。通过把Bean包装在一个适配器类中工作。适配器类被绑定到RMI注册表中,并且将请求代理给服务类。
服务端程序:
1 IHelloWorld.java POJO的接口
- public interface IHelloWorld {
- public String helloWorld();
- public String sayHelloToSomeBody(String someBodyName);
- }
2 HelloWorld.java POJO的实现
- public class HelloWorld implements IHelloWorld {
- @Override
- public String helloWorld() {
- return "Hello World!";
- }
- @Override
- public String sayHelloToSomeBody(String someBodyName) {
- return "Hello World!" + someBodyName;
- }
- }
3 spring配置文件rmi_server_context.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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
- <bean id="helloWorld" class="springapp.rmi.rmi.HelloWorld" />
- <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
- <property name="service" ref="helloWorld" />
- <!-- 定义服务名 -->
- <property name="serviceName" value="hello" />
- <property name="serviceInterface" value="springapp.rmi.rmi.IHelloWorld" />
- <property name="registryPort" value="8088" />
- </bean>
- </beans>
4 服务端启动RMI的代码HelloHost.java
- public class HelloHost {
- public static void main(String[] args) {
- ApplicationContext ctx = new ClassPathXmlApplicationContext(
- "rmi_server_context.xml");
- System.out.println("RMI服务伴随Spring的启动而启动了.....");
- }
- }
客户端
1 配置文件rmi_client_context.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-2.0.xsd">
- <bean id="helloWorld" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
- <property name="serviceUrl" value="rmi://10.87.40.141:8088/hello" />
- <property name="serviceInterface" value="springapp.rmi.rmi.IHelloWorld" />
- </bean>
- </beans>
2 客户端代码 HelloClient.java
- public class HelloClient {
- public static void main(String[] args) throws RemoteException {
- ApplicationContext ctx = new ClassPathXmlApplicationContext(
- "rmi_client_context.xml");
- IHelloWorld hs = (IHelloWorld) ctx.getBean("helloWorld");
- System.out.println(hs.helloWorld());
- System.out.println(hs.sayHelloToSomeBody("Lavasoft"));
- }
- }
转自:http://blog.csdn.net/arkblue/article/details/6237380
- Spring整合 RMI
- Spring整合RMI
- Spring整合 RMI
- Spring整合Rmi总结
- spring整合RMI
- Spring整合 RMI
- Spring整合 RMI
- Spring整合 RMI
- Spring整合RMI
- Spring整合 RMI
- spring整合rmi远程调用
- JAVA Spring RMI(1)--Spring整合Rmi总结
- spring整合RMI - Java远程方法调用
- Spring整合使用RMI-HelloWorld例子
- spring整合rmi 如何使用安全策略
- 关于spring 与rmi整合简单例子详解
- spring的rmi整合以及客户端和服务端搭建1.0
- spring的rmi整合以及客户端和服务端搭建2.0
- oracle完整性约束和索引
- 静态存储方式
- 互联网世界的9种基本的商业模式
- ajax 控件
- 使用truss、strace或ltrace诊断软件的"疑难杂症"
- Spring整合 RMI
- Java中的委托模式
- static静态变量的理解
- C++语言的url encode 和decode
- spring 3.0各包说明
- JEECMS后台任意文件编辑漏洞及拿shell
- Android版本进化史(信息图)
- gflags——一个命令行参数工具
- Android 待机流程解析