Listing 23-9. MBean for Hibernate Statistics
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<!-- Other code omitted -->
<!-- Spring MBean for JMX Monitoring -->
<bean id="appStatisticsBean" class="com.apress.prospring3.ch23.jmx.impl
.AppStatisticsImpl"/>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=ProSpring3ContactApp" value-ref="appStatisticsBean"/>
<entry key="bean:name=ProSpring3ContactApp-hibernate" value-ref=
"statisticsBean"/>
</map>
</property>
</bean>
<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled">
<value>true</value>
</property>
<property name="sessionFactoryJNDIName">
<value>sessionFactory</value>
</property>
</bean>
</beans>
In Listing 23-9, the changes are highlighted in bold. A new statisticsBean is declared, with
Hibernate's StatisticsService class as the implementation. This is how Hibernate supports exposing
statistics to JMX. Note the property sessionFactoryJNDIName, which should match the one defined in
Listing 23-8 (hibernate.session_factory_name). Then within the jmxExporter bean, another bean with
ObjectName bean:name=ProSpring3ContactApp-hibernate is declared that references the statisticsBean
bean.
Now the Hibernate statistics are enabled and available via JMX. After the application is reloaded and
the VisualVM is refreshed, you will be able to see the Hibernate statistics MBean. Clicking the node will
display the detail statistics on the right side. Note that for the information that is not of Java primitive
type (for example, a List), you can click in the field, which will expand the field to show the content.
Figure 23-11 shows the MBeans tab, with the mapped entity classes and the executed queries fields
expanded.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home