Spring中的RMI

服务端

通过org.springframework.remoting.rmi.RmiServiceExporter来暴露接口,供远程来调用

<?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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
        <!--提供的服务名称-->
        <property name="serviceName" value="HelloService" />
        <!--服务实现类引用-->
        <property name="service" ref="helloServiceImpl" />
        <!--暴露的服务接口-->
        <property name="serviceInterface"
            value="com.study.remoting.IHelloService" />
        <property name="registryPort" value="8080" />
        <property name="servicePort" value="8088" />
    </bean>
    <!--服务实现类对象-->
    <bean id="helloServiceImpl" class="com.study.remoting.HelloServiceImpl" />

</beans>

客户端

通过org.springframework.remoting.rmi.RmiProxyFactoryBean可以使用服务端暴露的服务

<?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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="helloService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <!--引用RMI服务的地址-->
        <property name="serviceUrl" value="rmi://192.168.1.103:8080/HelloService" />
        <!--服务端暴露的接口类-->
        <property name="serviceInterface"
            value="com.study.remoting.IHelloService" />
    </bean>

</beans>

使用spring对RMI的支持,可以非常容易地构建你的分布式应用!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容