简体   繁体   中英

NameNotFound on remote jmx call with rmi

I'm trying to remotely call jmx bean exposed by spring using this guide

but when I launch my client code, it fails to load application context with such error

Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: jmxrmi at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:357) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267) at org.springframework.jmx.support.MBeanServerConnectionFactoryBean.connect(MBeanServerConnectionFactoryBean.java:126) at org.springframework.jmx.support.MBeanServerConnectionFactoryBean.afterPropertiesSet(MBeanServerConnectionFactoryBean.java:114) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ... 38 more Caused by: javax.naming.NameNotFoundException: jmxrmi

Here is my server spring context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
        <map>
            <entry key="bean:name=testBean" value-ref="testBean" />
        </map>
    </property>
    <property name="assembler">
        <bean
            class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
            <property name="managedInterfaces">
                <value>jmx.IJmxTestBean</value>
            </property>
        </bean>
    </property>
    <property name="server" ref="mbeanServer" />
</bean>

<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
    <property name="port" value="1199" />
</bean>

<bean id="testBean" class="jmx.JmxTestBean">
    <property name="name" value="TEST" />
    <property name="age" value="100" />
</bean>

<bean id="serverConnector"
    class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry">
    <property name="objectName" value="connector:name=rmi" />
    <property name="serviceUrl"
        value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>

and this is my client spring context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="clientConnector"
    class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
    <property name="serviceUrl"
        value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
    <property name="objectName" value="bean:name=testBean" />
    <property name="proxyInterface" value="jmx.IJmxTestBean" />
    <property name="server" ref="clientConnector" />
</bean>

Any ideas?

Ok, this is not the issue with spring jmx, but with the jboss eap that I'm deploying the apps. This code runs perfectly fine when I launch the spring contexts as standalone clients or on jetty. Since I run this on JBoss EAP 6.2 then jmx by rmi is not supported I need to find another way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM