近日,负责开发一个远程调用的应用。该远程调用使用spring的rmi实现。
在最终的测试中,将同样的工程代码部署到两台应用服务器,但诡异的事情发生了,一台机器可以正常启动和调用Rmi服务,但是另外一台Web服务器报以下错误:
2008-03-02 17:52:19 [org.springframework.web.context.ContextLoader]-[ERROR] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aaaServiceExporter' defined in ServletContext resource [/WEB-INF/rmi-server.xml]: Invocation of init method failed; nested exception is java.rmi.server.ExportException: internal error: ObjID already in use
Caused by:
java.rmi.server.ExportException: internal error: ObjID already in use
at sun.rmi.transport.ObjectTable.putTarget(ObjectTable.java:168)
at sun.rmi.transport.Transport.exportObject(Transport.java:69)
at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:190)
at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:382)
at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:116)
at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:145)
at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:92)
at sun.rmi.registry.RegistryImpl.(RegistryImpl.java:78)
at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:164)
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:350)
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:326)
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:291)
at org.springframework.remoting.rmi.RmiServiceExporter.prepare(RmiServiceExporter.java:233)
at org.springframework.remoting.rmi.RmiServiceExporter.afterPropertiesSet(RmiServiceExporter.java:197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:83)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at com.caucho.server.http.Application.createServlet(Application.java:3114)
at com.caucho.server.http.Application.loadServlet(Application.java:3065)
at com.caucho.server.http.Application.initServlets(Application.java:1923)
at com.caucho.server.http.Application.init(Application.java:1849)
at com.caucho.server.http.VirtualHost.init(VirtualHost.java:728)
at com.caucho.server.http.ServletServer.initHosts(ServletServer.java:887)
at com.caucho.server.http.ServletServer.initInternal(ServletServer.java:729)
at com.caucho.server.http.ServletServer.init(ServletServer.java:538)
at com.caucho.server.http.ResinServer.init(ResinServer.java:415)
at com.caucho.server.http.ResinServer.main(ResinServer.java:1176)
at com.caucho.server.http.HttpServer.main(HttpServer.java:103)
后来经过仔细对比,发现两台Linux主机的host配置文件(/etc/hosts)不一致,出问题的机器存在一条不存在的host转向,最后删掉这条host记录,再次重启有问题的Web服务器,很顺利地就启动了Rmi服务,客户端调用也很成功!!
至此问题得到解决:)