Announcement Announcement Module
Collapse
No announcement yet.
How to access JMX Mbeans in Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access JMX Mbeans in Spring

    I am testing JMX support in Spring,
    I have an exporter, MbeanServer and a MBean in a application Context.xml.
    How can I test whether this bean has been registered as a MBean with the MBean Server. I mean I want to get the property of my registered bean. How do I do this.?
    Also, when I do a getBean on my Bean and then
    boolean isBean = JmxUtils.isMBean(jmxBean.getClass());
    it returns a false.
    Can someone help/.

    Following is my applicationContext.xml file:
    <bean id="exporter"
    class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="bean:name=testBean1" value-ref="testBean">
    </entry>
    </map>
    </property>
    <property name="server" ref="mbeanServer"/>

    <!-- Beans which are not exported via MBean exporter can be automatically detected-->
    <!--property name="autodetect" value="true"/-->
    </bean>

    <!-- Test JMX MBean -->
    <bean id="testBean"
    class="test.jmx.JmxTestBean">
    <property name="myValue">
    <value>20</value>
    </property>
    </bean>

    <!--MBean Server -->
    <bean id="mbeanServer"
    class="org.springframework.jmx.support.MBeanServer FactoryBean"/>

    Thanks,
    Poonam

  • #2
    If you want to check if bean has been registered within MBean server, you can simply provide MBeanProxyFactoryBean bean in the same context and try to invoke methods on it. It should delegate all the calls through MBean server to your exported MBean.

    Comment


    • #3
      getBean() will return false if the bean you are testing is not a user supplied MBean. Spirng-generated MBeans are never placed back into the ApplicationContext.

      To see if an MBean is registered, simply call MBeanServer.isRegistered() passing in the ObjectName of the bean you are registering.

      Rob

      Comment


      • #4
        How to access MBeans in Spring

        Thanks dvoytenko, I could access my MBean through the proxy interface.

        But I think Robh misunderstood my problem ...
        My question was when I try to check whether my Bean is a MBean using:

        JMXTestBean jmxBean = (JMXTestBean) ctx.getBean("testBean");
        boolean isBean = JmxUtils.isMBean(jmxBean.getClass());

        isMBean() method returns false. Ideally , it should return true because testBean is exported via the Exporter bean.(Have a look at the applContext.xml below).
        As per your suggestion Robh I tried
        MBeanServer.isRegistered() but here MBeanServer is an interface.
        Is there some other way by which I can check whether my testBean is an MBean. Is there some JMX Console?

        Thanks,
        Poonam.

        Comment


        • #5
          JDK 1.5 provides a build-in jmx console - jconsole. There are other alternatives especially for pre 1.5 vms, like mc4j or servlet-based (do a google).
          If you want to find a registered MBean inside the JMX space you can use the JMX queries.

          Comment


          • #6
            I am also trying to evaluate this particular feature of spring for our project.
            Can someone clarify on the MBeanProxyFactoryBean strategy Dimitry mentioned? The doc is very light in general.

            Thanks
            Rey

            Comment

            Working...
            X