客户端:
packageremote.rmi.client;
importremote.rmi.AccountService;
publicclassSimpleObject {
privateAccountServiceaccountService;
publicAccountService getAccountService() {
returnaccountService;
}
publicvoidsetAccountService(AccountService accountService) {
this.accountService= accountService;
}
}
XML
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEbeansPUBLIC"-//SPRING//DTD BEAN 2.0//EN""http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<beanid="object"class="remote.rmi.client.SimpleObject">
<propertyname="accountService">
<reflocal="accountService"/>
</property>
</bean>
<beanid="accountService"class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<propertyname="serviceUrl"value="rmi://localhost:8080/AccountService"></property>
<propertyname="serviceInterface"value="remote.rmi.AccountService"></property>
</bean>
</beans>
packageremote.rmi.client;
importjava.rmi.RemoteException;
importorg.springframework.core.type.filter.TypeFilter;
importorg.springframework.context.ApplicationContext;
importorg.springframework.context.support.ClassPathXmlApplicationContext;
publicclassClient {
/**
*@paramargs
*/
publicstaticvoidmain(String[] args) {
//TODOAuto-generated method stub
ApplicationContext context =newClassPathXmlApplicationContext(
"/remote/rmi/client/client.xml");
SimpleObject bject=(SimpleObject) context.getBean("object");
try{
object.getAccountService().getAccount("zhanghaijie");
}catch(RemoteException e) {
//TODOAuto-generated catch block
e.printStackTrace();
}
}
}
启动客户端的Client