我正在尝试使用本指南远程调用spring暴露的jmx
bean
但是当我启动我的客户端代码时,它无法加载应用程序上下文,并出现这样的错误
原因:java.io.IOException: Failed to retrieve RMIServer stub:javax.naming.NameNotFoundException: jmxrmijavax.management.remote.rmi.RMIConnector.connect (RMIConnector.java: 357)在javax.management.remote.JMXConnectorFactory.connect (JMXConnectorFactory.java: 267)在org.springframework.jmx.support.MBeanServerConnectionFactoryBean.connect (MBeanServerConnectionFactoryBean.java: 126)在org.springframework.jmx.support.MBeanServerConnectionFactoryBean.afterPropertiesSet (MBeanServerConnectionFactoryBean.java: 114)在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java: 1514)在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java: 1452)…由于:javax.naming.NameNotFoundException: jmxrmi
这是我的服务器spring上下文
<?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>
这是我的客户端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>
任何想法?
好,这不是spring jmx的问题,而是我正在部署应用程序的jboss eap的问题。当我将spring上下文作为独立客户端或在jetty上启动时,这段代码运行得非常好。由于我在JBoss EAP 6.2上运行此操作,因此不支持jmx by rmi,我需要找到另一种方法。