发表于: 2017-12-08 23:19:19

3 766


今日完成:

                  1)java RMI学习,java rmi其实是代理模式,我们调用的是远程端在客户端的代理对象。之前学习代理模式的时候记录过,具体见我的博客:

                                http://blog.csdn.net/zq17865815296/article/details/78450828


                   2)学习spring整合rmi

                         具体代码:

public interface HelloWorldService {//服务端接口

public String getMessage();
}

    

public class HelloWorldServiceImpl implements HelloWorldService {//服务端接口实现
public String getMessage() {
return "hello,这是rmi调用";
}
}

                  

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

<bean id="helloWorldService" class="com.distributed.rmi.service.HelloWorldServiceImpl" scope="prototype">
</bean>

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="helloWorldService"></property>
<property name="serviceName" value="helloWorld"></property>
<property name="serviceInterface" value="com.distributed.rmi.service.HelloWorldService"></property>
<property name="registryPort" value="9090"></property>
</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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="helloWorld" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:9090/helloWorld"></property>
<property name="serviceInterface" value="com.distributed.rmi.client.HelloWorld"></property>

<!--调用失败是否刷新远程-->
       <property name="refreshStubOnConnectFailure" value="true"></property>
</bean>

</beans>

   

public interface HelloWorld {//客户端接口
//只需要方法名称,方法参数一致就行
   //方法的返回值可以是服务端方法的父类
   String getMessage();
}

              综上:与java rmi相比,它不需要继承remote接口,也取消了很多的限制,更加灵活

             3)学习了maven分模块开发,网上很多资料,这里就展示个目录结构

                  

                其中service与web分离开了

  今日疑问:无


明日计划:

               将相关代码拷贝进去,通过spring rmi进行通信。

               整理这几天学习的并发知识。(周六周日时间比较多了)


返回列表 返回列表
评论

    分享到