Spring与RMI 集成,实现远程调用

来源:互联网 发布:股票大作手回忆录 知乎 编辑:程序博客网 时间:2024/06/06 00:06

服务器端配置

<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
       <property name="port" value="8011"/>
    </bean>
   <bean id="userSvcExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">   
        <property name="service" ref="userInfoImplRome"/>   
        <property name="serviceName" value="userDaoService"/>   
        <property name="serviceInterface" value="com.hisan.domel.UserInfo"/>   
        <property name="registry" ref="registry"/>
    </bean>   


service 接口实现类

serviceName 暴露在外界的服务名称

serviceInterface 需要实现的接口

registry 注册服务的端口,此端口不能与服务宿主(如:Tomcat)端口一致


接口类

public interface UserInfo {


String GetUser(int userid);
}

实现类

@Component("userInfoImplRome")
public class UserInfoImpl implements UserInfo {


public String GetUser(int userid) {
// TODO Auto-generated method stub
return userid+"ss";
}


}

客户端配置

<bean id="userDaoProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">   
        <property name="serviceUrl" value="rmi://localhost:8011/userDaoService"/>   
        <property name="serviceInterface" value="com.hisan.domels.UserInfo"/>   
    </bean>


 调用Controller

@Controller
public class OrderInfo {


@Resource(name="userDaoProxy")
private UserInfo userDaoProxy;  

@RequestMapping("getorder")
@ResponseBody
public String GetOrder(){

System.out.println(userDaoProxy.GetUser(9999));
return "98568564546546";
}
}

0 0