发表于: 2018-02-27 22:24:24

1 559


今天完成的事情

1.使用springrmi分离service和client。

service 端配置。

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
   <property name="serviceName" value="RemoteService"/>
   <property name="service" ref="studentServiceImp"/>
   <property name="serviceInterface" value="com.service.StudentService"/>
   <property name="registryPort" value="1199"/>
   <property name="servicePort" value="1199" />
</bean>

启动service

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StartService {
public static void main(String[] args){
System.setProperty("java.rmi.server.hostname","localhost");
       new ClassPathXmlApplicationContext("applicationContext.xml");
       System.out.println("Server 启动...");
   }
}

client端配置

<bean id="studentService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <property name="serviceUrl" value="rmi://127.0.0.1:1199/RemoteService"/>
    <property name="serviceInterface" value="com.service.StudentService"/>
</bean>

在client端写一个和service所暴露的相同接口,然后再controller中直接装配就可以使用了。


遇到的问题

1.Service启动服务出现报错。

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest


1.1stackoverflow中的答案是引用错误,查看并修改后没能解决。

1.2还有说是与tomcat中的servlet冲突,但是service不是一个web应用,没有使用tomcat,所以排除这个问题。


折腾了半天,还是没有解决这个问题。


今天的收获

1.学会了使用sprigrmi完成service和client的分离。


明天的计划

1.完成web端随机访问2个service。






返回列表 返回列表
评论

    分享到