Spring rmi实现简单例子
来源:互联网 发布:编程语言难易排名 编辑:程序博客网 时间:2024/05/16 23:42
不说废话了,直接上代码。
服务端:
pom.xml中加入spring依赖
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.1.6.RELEASE</version></dependency>
远程方法声明接口,IHelloWorld.java
package com.poreader.rmi;public interface IHelloWorld {public String say(String name);}
接口实现:HelloWorld.java
package com.poreader.rmi.impl;import com.poreader.rmi.IHelloWorld;public class HelloWorld implements IHelloWorld {public String say(String name) {return name + ":" + "HelloWorld";}}
Spring配置文件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.xsd"><bean id="helloWorld" class="com.poreader.rmi.impl.HelloWorld"></bean><bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"><property name="service" ref="helloWorld"></property><property name="serviceName" value="hello"></property><property name="registryPort" value="8088"></property><property name="serviceInterface" value="com.poreader.rmi.IHelloWorld"></property></bean></beans>
宿主运行Main
package com.poreader.main;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class App { public static void main( String[] args ) { ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml"); System.out.println("Service Running!!"); }}
客户端代码:
和服务端相同的远程接口声明
package com.poreader.rmi;public interface IHelloWorld {public String say(String name);}
Spring配置文件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.xsd"><bean id="helloWorld" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"><property name="serviceUrl" value="rmi://127.0.0.1:8088/hello" /><property name="serviceInterface" value="com.poreader.rmi.IHelloWorld" /></bean></beans>
调用Main
package com.poreader.main;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.poreader.rmi.IHelloWorld;public class App {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");IHelloWorld hs = (IHelloWorld) ctx.getBean("helloWorld");System.out.println(hs.say("suyang"));}}
0 0
- Spring rmi实现简单例子
- spring rmi 例子
- RMI简单例子
- RMI的简单例子
- 关于spring 与rmi整合简单例子详解
- RMI实现例子
- spring中实现rmi的一个例子及说明
- Python中实现远程调用(RPC、RMI)简单例子
- 基于RMI实现远程聊天功能的简单例子
- spring rmi 简单使用
- spring rmi简单实例
- Java RMI的简单例子
- Java RMI的简单例子
- Java RMI的简单例子
- 最简单的rmi例子
- spring rmi 实现
- Spring 实现RMI
- RMI简单实例与Spring集成RMI
- GCD学习(六) dispatch_async 和dispatch_sync
- 线程二-----------线程池的问题
- JNI(Java Native Interface)_03
- 几种RIA技术(富互联网应用程序)比较
- WebApp之PhoneGap控制器整体下拉上拽
- Spring rmi实现简单例子
- ORA-39700:database must be opened with UPGRADE option
- 网络零售和移动互联网搅动中国网络经济神经
- c++prime 练习 11.12
- JVM学习笔记(三):类的连接
- 常见算法:C语言求最小公倍数和最大公约数三种算法
- Adb&shell相关命令
- Xcode常用快捷键总结
- GCD学习(七) dispatch_apply