java.rmi.ConnectException: Connection refused to host with spring RMI -
i trying develop small spring rmi example.
i have created remote service interface , service follows,
calculation.java
package com; public interface calculation { string getname(string name); }
calimp:
package com; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class calimp implements calculation { static void init(){ applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml"); context.getbean("calculationbean"); } string names; public string getname(string name){ return names; } }
my application context file is
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="calculationbean" class="com.calimp"></bean> <bean class="org.springframework.remoting.rmi.rmiserviceexporter" destroy-method="destroy"> <property name="servicename" value="calculation"></property> <property name="service" ref="calculationbean"></property> <property name="serviceinterface" value="com.calculation"></property> <property name="replaceexistingbinding" value="true"></property> <property name="registryport" value="1199"></property> </bean> </beans>
then client classes follows,
client-beans.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="easyclient" class="com.tutorialspoint.client"> <property name="easyserver" ref="calculationbean"/> </bean> <bean id="calculationbean" class="org.springframework.remoting.rmi.rmiproxyfactorybean"> <property name="serviceurl" value="rmi://192.168.2.39:1199/calculation"></property> <property name="serviceinterface" value="com.calculation"></property> </bean> </beans>
client.java:
package com.tutorialspoint; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; import org.springframework.context.support.filesystemxmlapplicationcontext; import com.calculation; public class client { private calculation easyserver; public void seteasyserver(calculation easyserver) { this.easyserver = easyserver; } public string getdata(){ applicationcontext context = new classpathxmlapplicationcontext("client-beans.xml"); easyserver =(calculation) context.getbean("easyclient"); string name=easyserver.getname("praveen"); return name; } }
i tried test using following test utilities,
1) test.java
package com; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; public class test { /** * @param args */ public static void main(string[] args) { registry registry; string serveraddress="localhost"; string serverport="1199"; string text="hi"; system.out.println("sending "+text+" "+serveraddress+":"+serverport); try{ // “registry” registry=locateregistry.getregistry(serveraddress,(new integer(serverport)).intvalue()); registry.lookup("calculation") ; } catch(exception e) { e.printstacktrace(); } } }
when tried getting follwoing exception,even tried ,my ip "192.#.#.#" , still no luck.
sending hi localhost:1199 java.rmi.connectexception: connection refused host: localhost; nested exception is: java.net.connectexception: connection refused: connect @ sun.rmi.transport.tcp.tcpendpoint.newsocket(unknown source) @ sun.rmi.transport.tcp.tcpchannel.createconnection(unknown source) @ sun.rmi.transport.tcp.tcpchannel.newconnection(unknown source) @ sun.rmi.server.unicastref.newcall(unknown source) @ sun.rmi.registry.registryimpl_stub.lookup(unknown source) @ com.test.main(test.java:20) caused by: java.net.connectexception: connection refused: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(unknown source) @ java.net.abstractplainsocketimpl.doconnect(unknown source) @ java.net.abstractplainsocketimpl.connecttoaddress(unknown source) @ java.net.abstractplainsocketimpl.connect(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.<init>(unknown source) @ java.net.socket.<init>(unknown source) @ sun.rmi.transport.proxy.rmidirectsocketfactory.createsocket(unknown source) @ sun.rmi.transport.proxy.rmimastersocketfactory.createsocket(unknown source) ... 6 more
can 1 me in issue?