rmi object areald export

来源:互联网 发布:帝国cms 附件名称 编辑:程序博客网 时间:2024/05/16 08:06

普通RMI

1.实现类要extends UnicastRemoteObject,继承服务接口

2.客户段与服务器段 的接口要放在[同名]的包内

3.接口要extends Remote,接口方法要throws RemoteException;同样接口实现类的相应方法也要throws RemoteException(包括构造方法)

服务端代码: Naming.bind("rmi://localhost:1299/服务名字", new 实现类() );

客户代码: 接口 service = (接口)Naming.lookup("rmi://202.114.63.4:1299/服务名字");

 Spring RMI:

从普通RMI改编时要注意需要将实现类的extends UnicastRemoteObject去掉,否则会报错[org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'refreshService' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.rmi.server.ExportException: object already exported

 因为UnicastRemoteObject的作用就是生成stub object 

0 0
原创粉丝点击