Simplest way of accessing a Spring-exported JMX be

2019-08-26 09:38发布

问题:

I currently export my JMX beans using Spring and am quite happy with it. When running on another container ( e.g. Jetty, Tomcat ) I can simply connect using JConsole or JVisualVM and access my MBeans.

I have tried connecting to WebSphere using the instructions from How do you enable JMX in WebSphere with no success.

Is there a simpler way of accessing JMX beans on an application running on WebSphere Application Server 7.0 ?

回答1:

Not sure if you cannot connect to WebSphere7 JMX, or you can connect but do not see your exported MBeans. If it is the latter, I suspect you may be looking at the wrong MBeanServer instance, since WAS technically has more than one running.

Either way, to bypass all that nonsense, your best bet is to add a JMXConnectorServer definition in your Spring XML. That way, you control exactly how the JMX connections should be made, and it will use the standard J2SE RMI remoting, so you know your JConsole will connect to it easily.

Here's an example:

<bean id="MBeanServer"
    class="org.helios.jmx.util.MBeanServerFactory" lazy-init="false" factory-method="createMBeanServer">
    <constructor-arg type="java.lang.String" value="DefaultDomain" />
</bean>

<bean id="MBeanServerJMXUrl"
    class="javax.management.remote.JMXServiceURL" lazy-init="false">
    <constructor-arg type="java.lang.String" value="service:jmx:rmi:///jndi/rmi://localhost:8003/jmxrmi" />
</bean>

<bean id="RMIRegistry"
    class="java.rmi.registry.LocateRegistry" 
        lazy-init="false" 
        factory-method="createRegistry">
    <constructor-arg value="8003" />
</bean>


<bean id="MBeanServerConnector"
    class="javax.management.remote.JMXConnectorServerFactory" 
        lazy-init="false" 
        init-method="start"
        factory-method="newJMXConnectorServer"
        depends-on="RMIRegistry">
    <constructor-arg ref="MBeanServerJMXUrl" />
    <constructor-arg>
        <map/>
    </constructor-arg>
    <constructor-arg ref="MBeanServer" />
</bean>