zoukankan      html  css  js  c++  java
  • RMI

    1. 发布RMI服务

    在Spring配置文件中

     <!-- RMI配置参数-->
    <bean id="rmiServerHost" factory-method="setProperty" class="java.lang.System" lazy-init="false">
    <constructor-arg value="java.rmi.server.hostname"/>
    <constructor-arg value="${ipAddress}"/>
    </bean>

    <!--
    <bean factory-method="setProperty" class="java.lang.System" lazy-init="false">
    <constructor-arg value="java.rmi.dgc.leaseValue"/>
    <constructor-arg value="300000"/>
    </bean>

    <bean factory-method="setProperty" class="java.lang.System" lazy-init="false">
    <constructor-arg value="java.rmi.dgc.gcInterval"/>
    <constructor-arg value="900000"/>
    </bean>
    -->

    <!--
    接口IService
    类Service实现IService  
    -->

    <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="service" ref="Service" />      //服务接口的实现类 <property name="serviceName" value="MyService" />     //自定义服务名称 <property name="serviceInterface" value="IService" />   //服务接口 <property name="registryPort" value="9000" />      //端口    </bean>

    2. 客户端调用


    a.

    public
    static IService getService(String url){ try { RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); rmiProxyFactoryBean.setServiceUrl(url); rmiProxyFactoryBean.setServiceInterface(IService.class); rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true); rmiProxyFactoryBean.afterPropertiesSet(); IService service = (IService)rmiProxyFactoryBean.getObject();
    return service;
    }
    catch (Exception e){ throw new RuntimeException("获取程序服务[" + url + "]出错", e); } }

    //url的格式为 rmi://ip:port/ServiceName 如:rmi://127.0.0.1:9000/MyService

    b.

    在spring配置文件中
    <bean id="service" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <!-- 接收的rmi协议 -->
    <property name="serviceUrl" value="rmi://127.0.0.1:9000/MyService"/>
    <!-- 接收的rmi协议的接口 -->
    <property name="serviceInterface" value="IService"/>
    </bean>

    //注入到Test类中
    <bean id="test" class="com.qinh.Test">
      <property name="service" ref="service"/>
    </bean>
    
    




  • 相关阅读:
    asp.net后台导出excel的方法:使用response导出excel
    asp.net后台导出excel的方法一:使用response导出excel
    infragistics--web网站升级注意点
    infragistics--网站部署时webtab的tab前出现textbox
    Jewels and Stones
    To Lower Case
    Unique Email Addresses
    unique-morse-code-words
    很久没来博客园了。。。。
    Centos7 基础知识---------root文件夹下没有.ssh文件
  • 原文地址:https://www.cnblogs.com/QinH/p/4724732.html
Copyright © 2011-2022 走看看