Spring RMI的应用
来源:互联网 发布:深思考人工智能薪资 编辑:程序博客网 时间:2024/04/29 09:49
利用Spring来实现RMI,不用实现remote接口,也不用调用rmic编译stub和skeleton,
服务端可以定义org.springframework.remoting.rmi.RmiServiceExporter类完成RMI服务器实现.
客户端只要定义org.springframework.remoting.rmi.RmiProxyFactoryBean,告知rmi的url和接口
服务器实现:
接口:
IHello.java
package com.callan.Test;
public interface IHello {
public String hello(String name);
}
HelloImp.java
package com.callan.Test;
public class HelloImp implements IHello{
public String hello(String name){
return "hello:" + name;
}
}
服务端spring的配置:
<?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.callan.Test.HelloImp"/>
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service">
<ref bean="helloService"/>
</property>
<!-- 定义服务名 -->
<property name="serviceName">
<value>hello</value>
</property>
<property name="serviceInterface">
<value>com.callan.Test.IHello</value>
</property>
<property name="registryPort">
<value>8888</value>
</property>
</bean>
</beans>
客户端:
必须把服务端的IHello.class文件放到客户端一份
接下来看看客户端要如何实作,只要透过org.springframework.remoting.rmi.RmiProxyFactoryBean,并告知服务的URL、代理的接口即可,就好像在使用本地端管理的服务一样:
<?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="serviceClient"
class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface">
<value>com.callan.Test.IHello</value>
</property>
<!-- serviceUrl以rmi开头,定义服务器地址与端口和服务名 -->
<property name="serviceUrl">
<value>rmi://localhost:8888/hello</value>
</property>
</bean>
</beans>
客户端的调用
package com.callan.Test;
import org.springframework.context.ApplicationContext;
org.springframework.context.support.ClassPathXmlApplicationContext
public class RMIClient {
public static void main(String[] args) {
ApplicationContext content = new new ClassPathXmlApplicationContext("com/config/applicationContext.xml");
IHello iHello = (IHello)content.getBean("serviceClient");
System.out.println(iHello.hello("callan"));
}
}
- Spring RMI的应用
- Spring RMI的应用
- Spring与Rmi的集成与应用
- Spring对RMI支持的实际应用实例
- spring rmi 的使用
- spring包装的rmi
- Spring 企业级开发应用---------rmi和spring的整合的应用
- 通过Spring快速创建RMI应用
- Spring对rmi的封装
- RMI@SPRING的常见问题解决
- RMI@Spring的常见问题解决
- Spring中RMI的调用
- RMI@Spring的常见问题解决
- Spring rmi的简单demo
- spring集成rmi的注意事项
- spring 的 RMI 远程调用
- Spring对RMI的支持
- Spring对RMI的支持
- 交通灯系统
- 结果今天做的一件无语的事!!
- javascript:剪切板的使用(clipboardData.setData)和js中match函数
- 数据结构与算法实验源代码下载
- HDU 3487
- Spring RMI的应用
- MyEclipse输入代码打点没有提示的解决办法
- 字符串乱码
- Tomcat集群和负载均衡的实现(session同步)
- MySQL安装指南
- CRM对业务流程的三个要求
- linux mysql 命令
- Java Cache 开源项目
- 数据队列结构与操作