In Listing 23-3, the bean definition we need to add is highlighted in bold. First, the bean for the
POJO with statistics we want to expose is declared. Second, the jmxExporter bean with the
implementation class MBeanExporter is declared.
The MBeanExporter class is the core class within the Spring Framework's support for JMX. It's
responsible for registering Spring beans with a JMX MBean server (a server that implements JDK's
javax.management.MBeanServer interface, which exists in most commonly used web and JEE containers,
like Tomcat and WebSphere). When exposing a Spring bean as an MBean, Spring will attempt to locate a
running MBeanServer instance within the server and register the MBean with it. For the tc Server, which is
bundled with STS and built on top of Tomcat, an MBeanServer will be created automatically, so no
additional configuration is required.
Within the jmxExporter bean, the property beans defines the Spring beans we want to expose. It's a
Map, and any number of MBeans can be specified here. In our case, we would like to expose the
appStatisticsBean bean, which contains information about the contact application we want to show to
administrators. For the MBean definition, the key will be used as the ObjectName (the
javax.management.ObjectName class in JDK) for the Spring bean referenced by the corresponding entry
value. In the previous configuration, the appStatisticsBean will be exposed under the ObjectName
bean:name=ProSpring3ContactApp. By default, all public properties of the bean are exposed as attributes,
and all public methods are exposed as operations.
Now the MBean is available for monitoring via JMX. Let's proceed to set up VisualVM and use its
JMX client for monitoring purposes.
Setting Up VisualVM for JMX Monitoring
VisualVM is a very useful tool that can help in monitoring Java applications in various aspects. It's a free
tool that bundles with JDK 6 (the jvisualvm.exe file under the bin folder in the JDK installation folder). A
stand-alone version can also be downloaded from the project web site
(http://visualvm.java.net/download.html). We will use the stand-alone version in this chapter; at the
time of writing, the version is 1.3.3.
To install VisualVM, download the zip install file from the download site and extract it onto your
local computer. Then, under the folder bin, execute the program visualvm.exe on Windows (or execute
the visualvm script for Unix/Linux).
The VisualVM uses a plug-in system to support various monitoring functions. To support
monitoring MBeans of Java applications, we need to install the MBeans plug-in. To install the plug-in, in
VisualVM's menu, choose Tools Plug-ins, click the Available Plug-ins tab, check the plug-in VisualVM-
MBeans, and click the Install button, as shown in Figure 23-4.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home