java - Can not connect to server with RMI. Failed to retrieve RMIServer stub -
i have created project using spring3 , hibernate4. fails run.the code , root cause provided below.
bean.xml (server-side)
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="com.music" /> <tx:annotation-driven /> <bean id="mbeanexporter" class="com.alcatel.axs.container.spring.jmx.mbeanexporter"> <property name="beans"> <map> <entry key="application.music:service=musicmanager" value-ref="musicmanagementmbean"></entry> </map> </property> <property name="assembler" ref="assembler"></property> <property name="server" ref="mbeanserver"></property> </bean> <bean id="assembler" class="org.springframework.jmx.export.assembler.interfacebasedmbeaninfoassembler"> <property name="managedinterfaces"> <list> <value>com.music.mbean.musicmanagementmbean</value> </list> </property> </bean> <bean id="mbeanserver" class="org.springframework.jmx.support.mbeanserverfactorybean"> <property name="locateexistingserverifpossible" value="true"></property> </bean> <bean id="rmiregistry" class="org.springframework.remoting.rmi.rmiregistryfactorybean"> <property name="port" value="9670" /> </bean> <bean id="connectorserver" class="org.springframework.jmx.support.connectorserverfactorybean" depends-on="rmiregistry"> <property name="serviceurl" value="service:jmx:rmi://localhost/jndi/rmi://192.168.92.127:9670/music"> </property> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://192.168.92.127:3306/music?socket=/home/bhphuc/datas/9490/mysql.sock" /> <property name="username" value="root" /> <property name="password" value="mysql" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="annotatedclasses"> <list> <value>com.music.model.song</value> </list> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.mysqldialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> <bean class="org.springframework.dao.annotation.persistenceexceptiontranslationpostprocessor" /> </beans>
i deploy jboss server, success.but in client side connect server rmi false.
clien-side
public static void main( string[] args ) { try { jmxserviceurl url = new jmxserviceurl("service:jmx:rmi://192.168.92.127/jndi/rmi://192.168.92.127:9670/music"); system.out.println(url); jmxconnector jmxc = jmxconnectorfactory.connect(url); mbeanserverconnection mbeanserverconnection = (mbeanserverconnection) jmxc.getmbeanserverconnection(); objectname mbeanname = new objectname("bean:name=musicmanagement,type=musicmanagementmbean"); list<song> lstsong = (list<song>) mbeanserverconnection.invoke(mbeanname, "getall", null, null); (song song : lstsong) { system.out.println(song.getname()+song.getcategory()+song.getauthor()+song.getsinger() ); } } catch (malformedobjectnameexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (instancenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (mbeanexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (reflectionexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
i don't know how false?
my error:
java.io.ioexception: failed retrieve rmiserver stub: javax.naming.namenotfoundexception: music @ javax.management.remote.rmi.rmiconnector.connect(rmiconnector.java:357) @ javax.management.remote.jmxconnectorfactory.connect(jmxconnectorfactory.java:267) @ javax.management.remote.jmxconnectorfactory.connect(jmxconnectorfactory.java:226) @ com.music.client.app.main(app.java:31) caused by: javax.naming.namenotfoundexception: music @ com.sun.jndi.rmi.registry.registrycontext.lookup(registrycontext.java:116) @ com.sun.jndi.toolkit.url.genericurlcontext.lookup(genericurlcontext.java:203) @ javax.naming.initialcontext.lookup(initialcontext.java:411) @ javax.management.remote.rmi.rmiconnector.findrmiserverjndi(rmiconnector.java:1924) @ javax.management.remote.rmi.rmiconnector.findrmiserver(rmiconnector.java:1891) @ javax.management.remote.rmi.rmiconnector.connect(rmiconnector.java:274) ... 3 more
caused by: javax.naming.namenotfoundexception: music
the client doesn't have class available on classpath.