質問

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?

役に立ちましたか?

解決 2

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

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

他のヒント

I'm not familiar with that particular utility, but it looks like there is some weird overlap between the JNDI and JMX configurations. Why don't you simplify and just use the JDK's own JMXConnectorFactory ?

import javax.management.*;
import javax.management.remote.*;
...
JMXConnector connector = JMXConnectorFactory.connect("service:jmx:rmi://117.13.128.104/jndi/rmi://117.13.128.104:9308/agent/EODServer");
MBeanServerConnection connection = connector.getMBeanServerConnection();

Technically, if you need to, you can add an environment map into the mix by using:

JMXConnector connector = JMXConnectorFactory.connect("service:jmx:rmi://117.13.128.104/jndi/rmi://117.13.128.104:9308/agent/EODServer", environment);

...but it seems to me that the environment you are using is already implied by the default connector and the contents of your JMXServiceURL.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top