Spring MBean客户端认为MBean服务是RMI连接

时间:2014-01-03 01:15:33

标签: java spring rmi jmx mbeans

我在将自己的Spring MBean客户端连接到“Hello World!”时遇到问题。服务如JMX examples from Oracle所示。该服务和包含的客户端工作正常。

我认为这与RMI连接有关,当它期待其他东西时会回来...但我不知道解决方案是什么,或者即使这是正确的推断。

或者我是否以某种方式使用“错误的”MBeanServerConnectionFactoryBean?

有什么想法吗?

这是我对这个bean的spring配置:

<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-3.0.xsd">

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

<bean id="jmxClient"
      class="com.foo.jmx.MBeanPollingClient">
    <property name="mbeanServerConnection"
              ref="mBeanServerClient" />
</bean>
</beans>

这是我的实施代码:

import org.springframework.jmx.support.MBeanServerConnectionFactoryBean;

public class MBeanPollingClient {

    private MBeanServerConnectionFactoryBean mbeanServerConnection = null;

    public void setMbeanServerConnection ( MBeanServerConnectionFactoryBean m )
    {
        mbeanServerConnection = m;
    }

    public MBeanServerConnectionFactoryBean getMbeanServerConnection ( )
    {
        return mbeanServerConnection;
    }

}

我得到的错误:

  

引起:org.springframework.beans.factory.BeanCreationException:   在类路径中定义名为'jmxClient'的bean时出错   resource [jmx-beans.xml]:bean的初始化失败;嵌套   例外是   org.springframework.beans.ConversionNotSupportedException:失败   转换类型的属性值   'javax.management.remote.rmi.RMIConnector $ RemoteMBeanServerConnection'   要求的类型   'org.springframework.jmx.support.MBeanServerConnectionFactoryBean'for   property'mbeanServerConnection';嵌套异常是   java.lang.IllegalStateException:无法转换类型的值   [javax.management.remote.rmi.RMIConnector $ RemoteMBeanServerConnection]   要求的类型   [org.springframework.jmx.support.MBeanServerConnectionFactoryBean] for   property'mbeanServerConnection':没有匹配的编辑器或转换   战略发现

1 个答案:

答案 0 :(得分:1)

Spring将为您提供工厂提供的MBeanServerConnection。要修复错误,只需更改

private MBeanServerConnectionFactoryBean mbeanServerConnection;

private MBeanServerConnection mbeanServerConnection;