I'm having problems connecting my own Spring MBean client to the "Hello World!" service as seen in the JMX examples from Oracle. The service and included client are working fine.
I think it has to do with an RMI connection coming back when it's expecting something else... but I don't know what the solution would be, or even if that is a correct inference.
Or am I somehow using the "wrong" MBeanServerConnectionFactoryBean ?
Any ideas?
Here's my spring config for this bean:
<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>
Here's my implementing code:
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;
}
}
The error I'm getting:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmxClient' defined in class path resource [jmx-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection' to required type 'org.springframework.jmx.support.MBeanServerConnectionFactoryBean' for property 'mbeanServerConnection'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection] to required type [org.springframework.jmx.support.MBeanServerConnectionFactoryBean] for property 'mbeanServerConnection': no matching editors or conversion strategy found
Spring will give you an MBeanServerConnection
provided by the factory. To fix the error just change
private MBeanServerConnectionFactoryBean mbeanServerConnection;
to
private MBeanServerConnection mbeanServerConnection;