Feb 16 2009

Exposing MBeans with Spring

Published by Gilles at 9:21 pm under J2EE, Java, Spring

Automatic registration of MBeans

Any beans that are exported through the MBeanExporter and are already valid MBeans are registered as-is with the MBeanServer without further intervention from . MBeans can be automatically detected by the MBeanExporter by setting the autodetect property to true:

XML:
  1. <bean id="exporter" class="org.springframework..export.MBeanExporter">
  2. <property name="autodetect" value="true"/>
  3. </bean>
  4. <bean name=":mbean=true" class="mypackage.MyClass"/>

Here, the bean called spring:mbean=true is already a valid MBean and will be automatically registered by . By default, beans that are autodetected for registration have their bean name used as the ObjectName.

Remark: The documentation describes an auto-detection mechanism but omits a key fact. The bean name must have the form XXX:YYY=ZZZ
The example hints at that by using a name spring:mbean=true This is a rather strange name, implying that it is a magic value that indicates an auto detectable bean. The actual values do not matter with the parts of the name on either side of the colon being used to divide the beans into a two level heirarchy. This provides an easy way to structure the beans into a logical structure. Unfortunately, the rather clumsy name must be used for all references in the configuration. It is not possible to provide both a simple id and the specific name.

Pages: 1 2 3 4 5

5 Responses to “Exposing MBeans with Spring”

  1. KPon 25 Feb 2009 at 10:27 pm

    I was trying to set up a JMX managed standalone Spring application and the article helped a lot. Thanks!!!

  2. markon 06 Nov 2009 at 11:49 am

    Hello, I found your post about the Spring mbeans in the WebSphere 6.1. I am new to Spring and JMX and looking for a step by step guide to register and calling by wsadmin some Spring’s mbeans provided by the app developer. I read your post and do understand the websphere naming strategy but where do I need to place this class WebsphereNamingStrategy ?

    br
    Mark

  3. Gilleson 06 Nov 2009 at 11:59 am

    Hello Mark,
    You can place your WebsphereNamingStrategy class where you want. For my part, I place it in an “util” package…
    Cheers,
    Gilles

  4. markon 06 Nov 2009 at 12:24 pm

    Hello Gilles,
    Thanks a lot for a quick response. I just have one question if there is any possibility to enable the Spring’s mbean in WAS 6.1 without adding any new code to the project ? I do not have the source code and do not want to extend the EAR file.
    br
    Mark

  5. hoschilordon 26 Aug 2010 at 8:23 am

    excellent info, thanks!
    was trying to get this running on websphere and also figured out that websphere changes the objectnames of the mbeans..your sources saved a lot of time for me yeehaa :-)

Trackback URI | Comments RSS

Leave a Reply