- 浏览: 3100648 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (372)
- diy (4)
- linux (19)
- 杂项 (30)
- Swing (21)
- Java2D (21)
- Java3D (5)
- JavaIO (9)
- Java通讯 (5)
- Java设计模式 (3)
- Java多媒体 (0)
- Java算法 (7)
- Spring&EJB (29)
- Javaoffice (4)
- web前端 (23)
- javascript (1)
- php基础 (1)
- eclipse (3)
- 网站相关 (3)
- Apache (4)
- seo (12)
- db (28)
- server (3)
- api (4)
- 异常 (12)
- 计算机网络词汇表 (3)
- 随想录 (52)
- 收藏 (17)
- 犹太人的智慧 (3)
- 多线程 (1)
- jfreechart (7)
- Test (1)
- SorLib (30)
- ruby on rails (1)
最新评论
-
houyutao:
二三四都是错的空字符串也被匹配,*应该改成+
Java中判断字符串是否为数字的五种方法 -
mingyun:
但是 java.util.ArrayList 实现了 remo ...
java.lang.UnsupportedOperationException 解决方案 -
mingyun:
1.因为 Arrays.asList 返回的是 Arrays内 ...
java.lang.UnsupportedOperationException 解决方案 -
leolu007:
用java8新特性String testStr = " ...
java.lang.UnsupportedOperationException 解决方案 -
zhaohuaxishiwzw:
我之前所在的项目就是日本一家证券公司的项目。完全使用的是j2e ...
抛弃EJB(EJB2.0,EJB3.0,EJB4.0)
Spring使用RMI非常简单,甚至比直接使用RMI还简单。
第一:首先定义接口:
第二:实现接口
第三:在Spring配置文件中配置RMI服务
第四:启动RMI服务
第五:访问服务
第六:源码下载
http://www.zakisoft.com/?p=118
第一:首先定义接口:
import java.rmi.Remote; import java.rmi.RemoteException; import com.zakisoft.test.rmi.vo.User; public interface RmiUserService extends Remote{ User login(String username, String password) throws RemoteException; void create(String username, String password) throws RemoteException; }
import java.io.Serializable; public class User implements Serializable { private static final long serialVersionUID = -3017748605531466285L; private String username; private String password; public User(String username, String password) { this.username = username; this.password = password; } public String getUsername() { return username; } public String getPassword() { return password; } }
第二:实现接口
import java.net.MalformedURLException; import java.rmi.AlreadyBoundException; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.server.UnicastRemoteObject; import com.zakisoft.test.rmi.server.UserService; import com.zakisoft.test.rmi.server.UserServiceImpl; import com.zakisoft.test.rmi.vo.User; public class RmiUserServiceImpl extends UnicastRemoteObject implements RmiUserService { UserService service = new UserServiceImpl(); public RmiUserServiceImpl() throws RemoteException { } private static final long serialVersionUID = -7138363701504022490L; public void create(String username, String password) throws RemoteException { service.create(username, password); } public User login(String username, String password) throws RemoteException { return service.login(username, password); } public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException { LocateRegistry.createRegistry(1099); Naming.bind("rmi://localhost:1099/UserService", new RmiUserServiceImpl()); System.out.print("Service start"); } }
第三:在Spring配置文件中配置RMI服务
<bean id="userService" class="com.zakisoft.test.rmi.server.UserServiceImpl"></bean> <bean id="rmiService" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName" value="UserService"/> <property name="service" ref="userService"/> <property name="serviceInterface" value="com.zakisoft.test.rmi.server.UserService"/> <property name="registryPort" value="1099"/> </bean>
第四:启动RMI服务
public class SpringStartRmi { public static void main(String[] args) { new ClassPathXmlApplicationContext("zconfig.xml"); } }
第五:访问服务
import org.springframework.remoting.rmi.RmiProxyFactoryBean; import com.zakisoft.test.rmi.server.UserService; public class ClientSpringRmi { public static void main(String[] args) { RmiProxyFactoryBean factory = new RmiProxyFactoryBean(); factory.setServiceInterface(UserService.class); factory.setServiceUrl("rmi://localhost:1099/UserService"); factory.afterPropertiesSet(); UserService userService = (UserService)factory.getObject(); userService.create("test", "test"); System.out.println(userService.login("new_user_01", "new_password_01")); //userService.login("test", "test"); } }
第六:源码下载
http://www.zakisoft.com/?p=118
评论
1 楼
aijnecJay
2012-09-19
你这个例子举得把不用spring和用spring的混到一块了。。
第一步和第二步的接口和实现是不用spring的情况。
直接用第二步的main方法启动服务。
后面配了spring,直接用自己的接口和实现类注册进RmiServiceExporter即可。
第一步和第二步的接口和实现是不用spring的情况。
直接用第二步的main方法启动服务。
后面配了spring,直接用自己的接口和实现类注册进RmiServiceExporter即可。
发表评论
-
Spring,Hibernate,ResultSet和事务
2012-03-21 15:30 2928今天研究了一天的关于Spring,Hibernate,Resu ... -
Spring 注入 log4j
2012-01-12 17:21 6364如果打算将Log4j注入Spring的applicationC ... -
Spring DaoMethodAfterAdvice使用例子
2011-02-10 19:08 1268该拦截器会在bean的方法执行后被执行 import j ... -
Spring MethodBeforeAdvice使用例子
2011-02-10 19:05 14351MethodBeforeAdvice该拦截器会在调用dean的 ... -
Spring ThrowsAdvice使用例子
2011-02-10 19:01 9426ThrowsAdvice用于拦截异常 import ja ... -
Spring 消息注册发布的例子
2011-01-19 16:26 1403消息注册发布模式是我们常用的设计模式,Spring也实现了这个 ... -
FileSystemResource 参数为什么必须是绝对路径
2011-01-19 09:22 4553在使用FileSystemResource时,发现FileSy ... -
Spring的价值
2010-11-08 09:59 15411. Spring是一个非侵入性(non-invasive)框 ... -
Spring事务管理例子
2010-09-26 17:18 5836关于spring事务管理以及异常处理的帖子,本论坛争论颇多,各 ... -
Spring和iBatis整合的例子
2010-09-26 16:43 11005OR Mapping的思想相信不用多说大家都明白了,在这里我选 ... -
抛弃EJB(EJB2.0,EJB3.0,EJB4.0)
2010-09-25 17:28 9920关键词:EJB,JEEE,Spring,OO, ... -
J2EE架构图
2010-09-25 11:19 4737以下是J2EE架构图: -
J2EE的核心API与组件(没了EJB,J2EE还剩什么呢)
2010-09-25 10:56 1740J2EE是一种利用Java 2平台来简化企业解决方案的开发、部 ... -
Spring中加载xml配置文件的六种方式
2010-08-31 15:05 41407因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件 ... -
Spring框架的设计理念与设计模式(9)-策略模式
2010-08-31 13:34 2505关键词:Spring,设计模式,策略模式 上一章:Spring ... -
Spring框架的设计理念与设计模式(8)-代理模式
2010-08-31 13:32 2347关键词:Spring,设计模式,工厂模式,代理模式 上一章:S ... -
Spring框架的设计理念与设计模式(7)-Spring中AOP特性与实现
2010-08-31 13:26 3350关键词:Spring,AOP,Proxy,代理,拦截器 上一章 ... -
Spring框架的设计理念与设计模式(6)-Ioc容器及BeanFactory工厂
2010-08-31 13:20 4752关键词:Spring,Ioc,Bean,Context,Bea ... -
Spring框架的设计理念与设计模式(5)-Core组件
2010-08-31 13:10 2140关键词:Spring,Core,组件, ... -
Spring框架的设计理念与设计模式(4)-Context组件
2010-08-31 13:08 3300关键词:Context,组件,Spri ...
相关推荐
spring 与rmi 的整合 1.首先编写接口 interface : 这里的接口要继承Remote, 它是一个标识接口 2.编写实现类 3.编写main方法用于启动 service 4 配置spring文件 编写客户端测试类
spring和RMI分布式整合源码
spring+rmi非本地实现,包含客户端和服务端。
Spring集成rmi,实现远程服务,使用RMI集成实例
Spring整合RMI的使用,实现不同项目间方法的远程调用。
Spring-RMI (RMI调用, HTTP调用) 本人测试过了
为了避免业务逻辑重新开发,顾使用spring rmi,把所有的bean作为rmi服务暴漏出来,在客户端只需要把项目依赖过来就ok,或者把以前的接口导入过来。 参考文档:...
SpringRMI小例子代码,仅供参考。SpringRMI小例子代码,仅供参考。
spring集成的RMI的使用 简单使用
Spring Rmi的使用,对Spring RMI进行全访问的介绍,并介绍了其中的源代码部分
spring rmi 客户端 服务器 调用
本压缩文件包含两个Spring Java工程,演示了如何在Spring框架中使用RMI技术,欢迎下载!
java Spring+RMI入门程序源代码
闲来无事,做了个Spring RMI的小例子,非常易懂。
一个基于Spring的rmi实现,测试成功,可以远程调用。
rmi与spring整合实例
spring RMI 简单例子
很多新手问我怎么在Spring中使用RMI,我做了一个实例共享出来,其实网上有很多例子。
spring RMI 服务(自动把service发布为RMI服务),本例子加入了spring的预处理,可以根据自己的需要把指定位置的bean发布为 RMI 服务。
java rmi spring 使用实例,内涵服务端和客户端的源代码,测试可用。