【发布时间】:2014-01-20 14:33:03
【问题描述】:
我在将自己的 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 创建错误 资源 [jmx-beans.xml]:bean 初始化失败;嵌套的 例外是 org.springframework.beans.ConversionNotSupportedException:失败 转换类型的属性值 'javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection' 到所需类型 'org.springframework.jmx.support.MBeanServerConnectionFactoryBean' 对于 属性“mbeanServerConnection”;嵌套异常是 java.lang.IllegalStateException:无法转换类型的值 [javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection] 到所需类型 [org.springframework.jmx.support.MBeanServerConnectionFactoryBean] 为 属性“mbeanServerConnection”:没有匹配的编辑器或转换 找到策略
【问题讨论】:
-
您的问题又回到了前面。您查找的是一个 JMX 服务 bean 连接。例外是这样说的。真正的问题是为什么你认为它会是别的东西?
-
我使用的代码是直接从 Spring 示例中复制而来的——我认为它可以连接到 JMX Service Bean,因为这似乎是 Spring 连接器的全部前提。我不希望该属性成为 RMI 连接,但似乎认为它是例外 - 那就是返回的东西显然是 RMI 连接。我读错异常了吗?
标签: java spring rmi jmx mbeans