Search code examples
javaspringtomcatjmxspring-jmx

Spring JMX - Purpose of <context:mbean-server>


I am going through 'Chapter 20 - Managing Spring bean with JMX' from the book 'Spring In Action' 4th Edition by Craig Walls. There is one paragraph in this chapter on page 527.


From whence the MBean server?

As configured, MBeanExporter assumes that it’s running in an application server (such as Tomcat) or some other context that provides an MBean server. But if your Spring application will be running standalone or in a container that doesn’t provide an MBean server, you’ll want to configure an MBean server in the Spring context.

In XML configuration, the <context:mbean-server> element can handle that for you. In Java configuration, you’ll need to take a more direct approach and configure a bean of type MBeanServerFactoryBean() (which is what does for you in XML).


I have couple of questions on the above paragraph.

  1. Does it mean that when we are running the application on server like Tomcat, <context:mbean-server> declaration is no longer required?

  2. If above statement is true, who takes care of locating the MBean server when we are running on server like Tomcat or any other application server?

Thanks in advance!


Solution

  • That information is a little out of date...

    or some other context that provides an MBean server.

    Starting with Java 5 (if I recall correctly), the JVM has a built in MBeanServer. Prior to that, you had to be running in an App server, or provide some other MBeanServer such as mx4j.

    Regardless, you still need the server bean declaration; it tells Spring which server to use (the underlying MBeanServerFactoryBean's locateExistingServerIfPossible is set to true by the XML namespace parser. If that flag is false, the factory bean would create an additional MBeanServer.