无法使用RMI连接到服务器。无法检索RMIServer存根

时间:2015-04-10 03:53:12

标签: java jmx

我使用spring3和hibernate4创建了一个项目。但它无法运行。下面提供了代码和根本原因。

bean.xml(服务器端)

 <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>

我用jboss服务器部署它,它成功。但在客户端我用rmi连接到服务器是假的。

CLIEN侧

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);

        for (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();
    }

}

我不知道如何虚假?

我的错误:

 java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: music
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:357)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:226)
    at com.music.client.App.main(App.java:31)
Caused by: javax.naming.NameNotFoundException: music
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:116)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1924)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1891)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:274)
    ... 3 more

1 个答案:

答案 0 :(得分:0)

Caused by: javax.naming.NameNotFoundException: music

客户端在其CLASSPATH上没有该类可用。