Spring 集成 RMI

Maven

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-remoting</artifactId>
        </dependency>

服务端

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <bean id="hello" class="org.zln.bdrisk.col.HelloImpl"/>

    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <!-- RMI服务名称,可自定义服务名称 -->
        <property name="serviceName" value="helloService" />
        <!-- 导出实体 -->
        <property name="service" ref="hello" />
        <!-- 导出接口 -->
        <property name="serviceInterface" value="org.zln.bdrisk.col.IHello" />
        <!-- spring默认使用1099端口 -->
        <property name="registryPort" value="8888" />
    </bean>

</beans>

客户端

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <bean id="hello" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl" value="rmi://localhost:8888/helloService" />
        <property name="serviceInterface" value="org.zln.bdrisk.col.IHello" />
    </bean>
</beans>

说明:服务端只有Spring实例化了,RMI服务对象就会注册好等着被调用,客户端上填写好服务端的地址和服务名,然后从Spring容器中获取远程对象即可

RMI与Spring集成后,编写RMI服务类和普通的接口、实现没有区别,不再需要集成、跑出指定异常等

RMI的限制:1、客户端和服务端都必须是Java  2、对地址、端口的依赖

时间: 2024-08-08 20:17:44

Spring 集成 RMI的相关文章

Java之——Spring与RMI集成实现远程访问(插曲)

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/45972095 使用Spring对RMI的支持,可以非常容易地构建你的分布式应用.在服务端,可以通过Spring的org.springframework.remoting.rmi.RmiServiceExporter可以暴露你的服务:在客户端,通过org.springframework.remoting.rmi.RmiProxyFactoryBean可以使用服务端暴露的服务

Hessian与Spring集成

简介: Hessian是一个简单的连接Web服务的二进制协议. 客户端和服务端不依赖于其他任何jar,比起webService 它显得轻量许多,比如使用xfire包含核心库和客户端的jar,大小达到了10M ,而最新的hessian-4.0.7  jar大小也只有不到400K. 更适合二进制的传输,比起webService.Hessian的 传输速度要高于webService. 支持Java,c#,Flex(actionscrpit) 配置: Hessian的访问分为客户端和服务端,首先都要有H

Quartz与Spring集成——创建调度器

前言 在<Quartz与Spring集成-- SchedulerFactoryBean的初始化分析>一文中介绍过Spring集成Quartz时的初始化过程,其中简单的提到了创建调度器的方法createScheduler.本文将着重介绍Quartz初始化时是如何创建调度器的. 创建调度器 这里从createScheduler的实现(见代码清单1)来分析,其处理步骤如下: 设置线程上下文的类加载器: 通过单例方法获取SchedulerRepository的实例(见代码清单2): 从调度仓库实例Sc

RabbitMQ安装和使用(和Spring集成)

一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 Eralng OTP For Windows (vR16B03) 运行安装 Rabbit MQ Server Windows Installer (v3.2.3) 具体操作步骤参考:在 Windows 上安装Rabbit MQ 指南 本人遇到的问题 当安装RabbitMQ后,使用rabbitmqctl

spring集成quartz

spring集成quartz 注意:出现异常"Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class" Spring3.0不支持Quartz2.0,因为org.quartz.CronTrigger在2.0从class变成

Hessian入门(包括与Spring集成)

A.纯Hessian接口开发步骤 Hessian-JAVA服务器端必须具备以下几点: * 1.包含Hessian的jar包(hessian-4.0.37.jar) * 2.设计一个接口,用来给客户端调用(IHessian.java) * 3.实现该接口的功能(IHessianImpl.java) * 4.配置web.xml,配好相应的Servlet(web.xml) * 5.对象必须实现Serializable接口(Foo.java) Hessian-JAVA服务端代码预览图: 1.包含Hess

Struts2+Spring集成合并

前边单独总结了Struts2,Spring和Ibaits框架了,那么怎么结合使用呢?这次先来看一下Sturts2和Spring的集成合并.其实挺简单的,就是导入各自的jar包以及连接彼此的jar包,分好彼此的工作就可以了. 好看一下Struts2+Spring的集成方案!  Struts2和Spring集成有两种方案,是根据action的创建来划分的!  方案一,Struts2负责流程,Spring负责对象的创建:Action由Struts2框架负责创建:Service由Spring框架负责创建

Java Persistence with MyBatis 3(中文版) 第五章 与Spring集成

MyBatis-Spring是MyBatis框架的子模块,用来提供与当前流行的依赖注入框架Spring的无缝集成. Spring框架是一个基于依赖注入(Dependency Injection)和面向切面编程(Aspect Oriented Programming,AOP)的Java框架,鼓励使用基于POJO的编程模型.另外,Spring提供了声明式和编程式的事务管理能力,可以很大程度上简化应用程序的数据访问层(data access layer)的实现.在本章中,我们将看到在基于Spring的

spring集成Log4j以及log4j配置简要说明

Spring集成: web.xml中配置log4j <context-param> <param-name>log4jConfigLocation</param-name> <param-value>WEB-INF/log4j.xml</param-value></context-param> <!-- 加载Spring框架中的log4j监听器Log4jConfigListener --><listener>