Search code examples
springjmxmbeans

InvocationException on connecting to MBean server from Spring


I am trying to connect to MBean server from my Spring application. Below is the code:

public void connect() throws Exception {

    MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
    bean.setConnectOnStartup(false);

    Properties environment = new Properties();

    environment.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
    environment.put("java.naming.provider.url", "rmi://117.13.128.104:9308");
    environment.put("jmx.remote.jndi.rebind", "true");

    bean.setEnvironment(environment);
    bean.setServiceUrl("service:jmx:rmi://117.13.128.104/jndi/rmi://117.13.128.104:9308/agent/EODServer");
    bean.afterPropertiesSet();

    MBeanServerConnection server = (MBeanServerConnection)bean.getObject();

    System.out.println("test"); // After bean.getObject() - Debug pointer on this line.
}

The debug pointer is set after bean.getObject() method call.

On debugging above code, I am getting below value for MBeanServerConnection server:

com.sun.jdi.InvocationException occurred invoking method.

Values of Environment and ServiceUrl of MBeanServerConnectionFactoryBean are set correctly then why it's not connecting to MBean Server?


Solution

  • It's get resolved after setting java.rmi.server.ignoreStubClasses system property to true.

    System.setProperty("java.rmi.server.ignoreStubClasses", "true");