1. 程式人生 > >用Spring動態呼叫RMI遠端物件

用Spring動態呼叫RMI遠端物件

// 不需要通過BeanFactory直接動態呼叫遠端物件

DistributeCenterBO distributeCenterBO = null;
RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceInterface(DistributeCenterBO.class);
rmiProxyFactoryBean.setServiceUrl(
"rmi://localhost:1199/DistributeCenterBO");
try {
rmiProxyFactoryBean.afterPropertiesSet(); //更改ServiceInterface或ServiceUrl之後必須呼叫該方法,來獲取遠端呼叫樁

} catch (Exception ex) {
}

if (rmiProxyFactoryBean.getObject() instanceof DistributeCenterBO) {
distributeCenterBO = (DistributeCenterBO)
rmiProxyFactoryBean.getObject();
distributeCenterBO.register(SubscriberImpl.subscriberId);
}