Tuesday, April 27, 2010

HibernateJMX with Spring

Hibernate Mbean is nice way to get runtime Hibernate Stat. Here is how to publish Hibernet Mbean to Tomcat Mbean server with Spring. Once Mbean are published, it can be access through Jconsole.

Tomcat setup:

JAVA_OPTS=" -Dcom.sun.management.jmxremote.port=9002  -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false  -Djava.awt.headless=true" 

Spring config:

<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<entry key="Hibernate:name=statistics">
<ref local="statisticsBean">

<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled">
<!-- Change this to match you own system if needed -->
<property name="sessionFactory"><ref local="sessionFactory"></ref>

Hibernate property:
<prop key="hibernate.generate_statistics">true</prop>

No comments:

Post a Comment