也许这个问题看起来很重复,但是我花了很多时间阅读论坛并试图弄清楚我的代码出了什么问题。运行服务器时,我收到log4j机制提供的以下消息:
21 Apr 2019 14:39:11,707 DEBUG org.springframework.remoting.rmi.RmiServiceExporter 404 getRegistry - RMI registry access threw exception
我得到以下两个例外:
java.rmi.ConnectException: Connection refused to host: 169.254.144.79; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619) ~[?:1.8.0_201]
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) ~[?:1.8.0_201]
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) ~[?:1.8.0_201]
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338) ~[?:1.8.0_201]
at sun.rmi.registry.RegistryImpl_Stub.list(RegistryImpl_Stub.java:85) ~[?:1.8.0_201]
at org.springframework.remoting.rmi.RmiServiceExporter.testRegistry(RmiServiceExporter.java:421) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:400) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:378) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.remoting.rmi.RmiServiceExporter.getRegistry(RmiServiceExporter.java:337) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.remoting.rmi.RmiServiceExporter.prepare(RmiServiceExporter.java:268) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.remoting.rmi.RmiServiceExporter.afterPropertiesSet(RmiServiceExporter.java:230) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) [spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) [spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) [spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85) [spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at StartServer.main(StartServer.java:19) [classes/:?]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[?:1.8.0_201]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[?:1.8.0_201]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_201]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_201]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_201]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[?:1.8.0_201]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_201]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_201]
at java.net.Socket.connect(Socket.java:538) ~[?:1.8.0_201]
at java.net.Socket.<init>(Socket.java:434) ~[?:1.8.0_201]
at java.net.Socket.<init>(Socket.java:211) ~[?:1.8.0_201]
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) ~[?:1.8.0_201]
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148) ~[?:1.8.0_201]
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) ~[?:1.8.0_201]
... 24 more
spring-server.xml文件中的代码是:
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="Reservation"/>
<property name="service" ref="reservationService"/>
<property name="serviceInterface" value="services.IReservationServer"/>
<property name="servicePort" value="1099"/>
</bean>
我尝试了多种方法来解决该问题,包括设置以下两个属性:
<property name="registryHost" value="169.254.144.79"/>
<property name="registryPort" value="1099"/>
我还设置了此属性:
System.setProperty("java.rmi.server.hostname","169.254.144.79");
或
System.setProperty("java.rmi.server.hostname","127.0.0.1");
我什至禁用了Windows Defender防火墙,但没有任何效果。