客户端:
package remote.rmi.client;
import remote.rmi.AccountService;
public class SimpleObject {
private AccountService accountService;
public AccountService getAccountService() {
return accountService;
}
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
}
XML
xml version="1.0" encoding="UTF-8"?>
DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" >
<beans>
<bean id="object" class="remote.rmi.client.SimpleObject">
<property name="accountService">
<ref local="accountService"/>
property>
bean>
<bean id="accountService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:8080/AccountService">property>
<property name="serviceInterface" value="remote.rmi.AccountService">property>
bean>
beans>
package remote.rmi.client;
import java.rmi.RemoteException;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext(
"/remote/rmi/client/client.xml");
SimpleObject bject=(SimpleObject) context.getBean("object");
try {
object.getAccountService().getAccount("zhanghaijie");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
启动客户端的Client
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7528999/viewspace-255449/ ,如需转载,请注明出处,否则将追究法律责任。