zoukankan      html  css  js  c++  java
  • 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、对地址、端口的依赖

  • 相关阅读:
    生活小记--工作一年后的菜鸡
    git使用笔记-git项目的建立及配置、创建子分支及独立分支、分支重命名
    React-leaflet在ant-design pro中的基本使用
    ionic新入坑-环境搭建+新建项目+打开低版本项目处理
    canvas绘制圆心扇形可组成颜色随机的七色小花
    取所选当前时间前十二个月的数据
    win10被微软流氓更新后编译基于visual Studio的web项目报[ArgumentOutOfRangeException: 指定的参数已超出有效值的范围
    浅析__proto__、prototype
    JavaScript数据类型
    异步与多线程实现不阻塞区别
  • 原文地址:https://www.cnblogs.com/sherrykid/p/5917983.html
Copyright © 2011-2022 走看看