1、SOAP/RPC风格的Webservice(通过XFire),Hessian, PHPRPC都需要Servlet模型的支持,但是Play!不支持Servlet(或许有变通的方法?),所以,还是使用RMI这种技术
2、Play!的Model类,不是纯的POJO,继承了JPASupport,作为远程对象传递时,可能会产生
10:38:16,956 ERROR ~ failed to lazily initialize a collection of role: models.User.posts, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: models.User.posts, no session or session was closed
这样的错误,因此,要定义 POJO的VO/DTO对象,做为远程传递对象
3、VO对象,因为要通过RMI传递,必须要实现Serializable接口,并且最好在类中指定serialVersionUID,象这样
private static final long serialVersionUID = 1L;
可以避免Server和Client之间同种对象版本不一样的错误
4、通过Spring封装并提供RMI的服务。需要自定义一个job,随Play!启动而启动,初始化RMI服务,象这样
//注册RMI
play.modules.spring.Spring.getBean("postServiceRmi");
5、RMI实现类,无法象Play!的Controller类一样,直接调用Model对象,Guillaume Bort的解释是
“I think that the RMI server call your code in a non managed thread.
You need to wrap your code in a play.Invoker.Invocation object. “
需要使用以下的变通方法
So it is almost the same code than Jobs. Btw you could directly use jobs:
public class RetrievePostsByUserJob extends Job<List<PostVO>> {
private Long id;
public RetrievePostsByUserJob(Long id) {
this.id = id;
}
public List<PostVO> doJobWithResult() {
... your code here
return list;
}
}
and then use the job in your RMI server:
public List<PostVO> getPostsByUserId(Long id) {
return new RetrievePostsByUserJob(id).now().get();
}
分享到:
相关推荐
rmi与spring整合实例
本压缩文件包含两个Spring Java工程,演示了如何在Spring框架中使用RMI技术,欢迎下载!
在Spring中输出、访问RMI,之前做的Demo,希望对大家有所帮助!
SpringRMI小例子代码,仅供参考。SpringRMI小例子代码,仅供参考。
1. 远程调用RMI(Remote Method Invocation): 通过使用 RmiProxyFactoryBean 和 RmiServiceExporter,并且,Spring支持两个传统的RMI(使用 java.rmi.Remote接口和java.rmi.RemoteException)和通过RMI调用器实现的...
Spring集成rmi,实现远程服务,使用RMI集成实例
spring集成的RMI的使用 简单使用
闲来无事,做了个Spring RMI的小例子,非常易懂。
spring和RMI分布式整合源码
spring rmi 客户端 服务器 调用
spring RMI 简单例子
java rmi spring 使用实例,内涵服务端和客户端的源代码,测试可用。
为了避免业务逻辑重新开发,顾使用spring rmi,把所有的bean作为rmi服务暴漏出来,在客户端只需要把项目依赖过来就ok,或者把以前的接口导入过来。 参考文档:...
教您如何创建JAVA RMI ,创建Spring RMI。
spring 与rmi 的整合 1.首先编写接口 interface : 这里的接口要继承Remote, 它是一个标识接口 2.编写实现类 3.编写main方法用于启动 service 4 配置spring文件 编写客户端测试类
spring RMI 服务(自动把service发布为RMI服务),本例子加入了spring的预处理,可以根据自己的需要把指定位置的bean发布为 RMI 服务。
spring+rmi非本地实现,包含客户端和服务端。
基于spring rmi的一些小改造,在原基础上加入了线程池控制线程数。
Spring Rmi的使用,对Spring RMI进行全访问的介绍,并介绍了其中的源代码部分
Spring-RMI (RMI调用, HTTP调用) 本人测试过了