Возможно, вопрос выглядит как дубликат, но я потратил много часов, читая форумы и пытаясь выяснить, что не так с моим кодом. Когда я запускаю сервер, я получаю следующее сообщение, предоставляемое механизмом 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, но ничего не получалось.