Spring rmi的简单demo
来源:互联网 发布:电子书在线制作软件 编辑:程序博客网 时间:2024/05/20 18:42
(1)定义接口:
(2)接口实现:
(3)rmi-server.xml
(4)rmi-client.xml
(5)测试
- package com.logcd.spring.rmi;
- public interface HelloService {
- public String doHello(String name);
- }
package com.logcd.spring.rmi;public interface HelloService {public String doHello(String name);}
(2)接口实现:
- package com.logcd.spring.rmi;
- public class HelloServiceImpl implements HelloService{
- public String doHello(String name) {
- return "Hello , " + name;
- }
- }
package com.logcd.spring.rmi;public class HelloServiceImpl implements HelloService{public String doHello(String name) {return "Hello , " + name;}}
(3)rmi-server.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
- "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="helloService" class="com.logcd.spring.rmi.HelloServiceImpl"/>
- <!--RmiServiceExporter显示地支持使用RMI调用器暴露任何非RMI服务-->
- <bean id="serviceExporter"
- class="org.springframework.remoting.rmi.RmiServiceExporter">
- <property name="service" ref="helloService"/>
- <property name="serviceInterface"
- value="com.logcd.spring.rmi.HelloService"/>
- <!--定义要暴露的服务名可以与输出的bean不同名,客户端通过这个名字来调用服务-->
- <property name="serviceName" value ="HelloService"/>
- <!--覆盖RMI注册端口号(1099),通常应用服务器也会维护RMI注册,最好不要冲突-->
- <property name="registryPort" value="1199"/>
- </bean>
- </beans>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloService" class="com.logcd.spring.rmi.HelloServiceImpl"/><!--RmiServiceExporter显示地支持使用RMI调用器暴露任何非RMI服务--> <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="service" ref="helloService"/> <property name="serviceInterface" value="com.logcd.spring.rmi.HelloService"/> <!--定义要暴露的服务名可以与输出的bean不同名,客户端通过这个名字来调用服务--> <property name="serviceName" value ="HelloService"/> <!--覆盖RMI注册端口号(1099),通常应用服务器也会维护RMI注册,最好不要冲突--> <property name="registryPort" value="1199"/> </bean> </beans>
(4)rmi-client.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
- "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <!--使用RmiProxyFactoryBean连接服务端-->
- <bean id="serviceProxy"
- class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
- <property name="serviceUrl"
- value="rmi://localhost:1199/HelloService"/>
- <property name="serviceInterface"
- value="com.logcd.spring.rmi.HelloService"/>
- </bean>
- </beans>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><!--使用RmiProxyFactoryBean连接服务端--> <bean id="serviceProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:1199/HelloService"/> <property name="serviceInterface" value="com.logcd.spring.rmi.HelloService"/> </bean></beans>
(5)测试
- package com.logcd.spring.rmi;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class TestSpringRMI {
- public static void main(String args[]){
- ApplicationContext context= new ClassPathXmlApplicationContext(
- new String[]{"rmi-server.xml","rmi-client.xml"});
- HelloService service = (HelloService)context.getBean("serviceProxy");
- System.out.println(service.doHello("logcd"));
- }
- }
package com.logcd.spring.rmi;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestSpringRMI {public static void main(String args[]){ ApplicationContext context= new ClassPathXmlApplicationContext(new String[]{"rmi-server.xml","rmi-client.xml"}); HelloService service = (HelloService)context.getBean("serviceProxy"); System.out.println(service.doHello("logcd"));}}
转自:http://log-cd.iteye.com/blog/213908
- Spring rmi的简单demo
- Spring Rmi Demo
- spring简单的demo
- Spring的简单Demo
- RMI的简单解读和具体实现Demo
- spring rmi 简单使用
- spring rmi简单实例
- spring mvc简单的demo
- RMI简单实例与Spring集成RMI
- Spring rmi实现简单例子
- spring rmi 的使用
- spring包装的rmi
- Spring RMI的应用
- Spring RMI的应用
- java 简单 的 RMI
- RMI简单的HelloWorld
- RMI的简单实现
- RMI的简单实现
- eclipse中project的分类问题
- 2013寒假练习 快速幂三弹连发 A^B mod C v1.0-3.0
- html <textarea>标签的使用
- 游标那点小事
- Java的序列化ID的作用
- Spring rmi的简单demo
- python学习笔记2:数据结构
- rpm is not signed
- 多进程编程:Perl与C进程间的消息队列通信
- jsp,html点滴;checbox勾选
- 解决Devexpress中 条件颜色与多选颜色重叠的问题
- android 实现发送彩信方法 (MMS),非调用系统界面
- 研究人员正开发永不会崩溃的计算机
- 精确获取时间(QueryPerformanceCounter)