Spring利用代理,完成RMI服务端和客户端的开发
来源:互联网 发布:网络直销流程 编辑:程序博客网 时间:2024/06/05 22:35
Spring利用代理,完成RMI服务端和客户端的开发,可以使任意POJO的方法进行暴露
服务接口:
服务实现:
服务端配置文件:applicationContext.xml
客户端配置文件:applicationContext-client.xml
服务端测试代码:
运行后并没有立即退出,因为远程服务是运行在后台的,一直等待客户端的链接
客户端:
运行后,可以看到后台打印出了,服务端输出的Hello World
---------------------------------------下面注释为qlp3643_1加-----------------------------------------------------
其中需要特别注别的是:
注册端口:registryPort 注册端口是RMI注册远程服务的端口。
服务端口:servicePort RMI的通讯需要的传送数据的端口。如果没有设置servicePort,则使用随机端口。
服务接口:
package test.SimpleRMI;public interface HelloWorld { public String getMessage();}
服务实现:
package test.SimpleRMI;public class HelloWorldImpl implements HelloWorld { public String getMessage() { return "hello world"; }}
服务端配置文件: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-2.0.xsd"><bean id="helloWorldService" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName"> <value>HelloWorld</value> </property> <property name="service"> <bean class="test.SimpleRMI.HelloWorldImpl"/> </property> <property name="serviceInterface"> <value>test.SimpleRMI.HelloWorld</value> </property> <property name="registryPort"> <value>9000</value> </property> <property name="servicePort"> <value>9001</value> </property> </bean></beans>
客户端配置文件: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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"><bean id="helloworldService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl"> <value>rmi://localhost:9000/HelloWorld</value> </property> <property name="serviceInterface"> <bean class="test.SimpleRMI.HelloWorld"></bean> </property></bean><bean id="helloworldClient" class="test.SimpleRMI.HelloWorldClient"> <property name="helloworldService"> <ref local="helloworldService"/> </property></bean></beans>
服务端测试代码:
运行后并没有立即退出,因为远程服务是运行在后台的,一直等待客户端的链接
package test.SimpleRMI;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test { /** * @param args */ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("ch16/SimpleRMI/applicationContext.xml"); System.out.println("host stated..."); }}
客户端:
package test.SimpleRMI;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class HelloWorldClient { private HelloWorld helloworldService; public HelloWorld getHelloworldService() { return helloworldService; } public void setHelloworldService(HelloWorld helloworldService) { this.helloworldService = helloworldService; } public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("test/SimpleRMI/applicationContext-client.xml"); HelloWorldClient helloWorldClient=(HelloWorldClient)context.getBean("helloworldClient"); helloWorldClient.run(); } public void run(){ System.out.println(helloworldService.getMessage()); }}
运行后,可以看到后台打印出了,服务端输出的Hello World
---------------------------------------下面注释为qlp3643_1加-----------------------------------------------------
其中需要特别注别的是:
<property name="registryPort"> <value>9000</value> </property> <property name="servicePort"> <value>9001</value> </property>
注册端口:registryPort 注册端口是RMI注册远程服务的端口。
服务端口:servicePort RMI的通讯需要的传送数据的端口。如果没有设置servicePort,则使用随机端口。
阅读全文
0 0
- Spring利用代理,完成RMI服务端和客户端的开发
- spring的rmi整合以及客户端和服务端搭建1.0
- spring的rmi整合以及客户端和服务端搭建2.0
- Spring集成Thrift,实现服务端和客户端代理
- 简单服务端和客户端的开发
- java rmi 代理包开发 ,spring rmi 设置超时
- 2 Python 利用socket实现的服务端和客户端
- 利用Netty进行客户端和服务端交互的入门示例
- Thrift学习笔记(6)--Spring集成Thrift,实现服务端和客户端代理
- spring + cxf 的webservice服务端和客户端功能
- spring rmi代理性能
- 利用myeclipse建立webservice服务端和客户端
- java开发axis 1.4 的webserver客户端和服务端
- ExtJS5.1学习笔记10——Proxy代理的使用(客户端代理和服务端代理)
- spring jmx客户端 和服务端配置
- 解决spring RMI服务端断开导致客户端链接被拒绝问题
- SOA之利用axis2开发服务端和客户端并保持跟提供的wsdl文件结构格式一致的开发详解
- 服务端开发or客户端开发的选择
- javascript开发:ES5与ES6的“this”深入分析
- 菜逼学python
- java工作流-流程设计
- 从文件服务器下载图片文件
- RANSAC算法
- Spring利用代理,完成RMI服务端和客户端的开发
- 移动端和PC端遮罩层弹出后,页面禁止滚动的解决方法
- 沉浸状态栏
- JDK、JVM、JRE的区别
- UML的9种图例解析
- 决策树
- NLP参考资源
- git 简单命令记录
- Lock与Synchronized