如何在Spring 3.0应用程序中配置Hibernate统计信息? [英] How to configure Hibernate statistics in Spring 3.0 application?
问题描述
我们如何进行配置,以便在基于Spring MVC的Web应用程序中通过JMX获得Hibernate统计信息。有没有更好的方法来跟踪Hibernate的性能。
How do we configure such that we obtain Hibernate statistics through JMX in Spring MVC based web applications. Is there any better way of tracking Hibernate performance.
推荐答案
设置 hibernate.generate_statistics $ c $ (在
persistence.xml
中或 hibernate.cfg.xml中
Set hibernate.generate_statistics
to true
(either in persistence.xml
or in hibernate.cfg.xml
or in your session factory bean configuration). Then register this bean:
<bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled" value="true" />
<property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
</bean>
(如果您不使用JPA,只需指定 sessionFactory
bean而不是通过EMF获取它)
(If you are not using JPA, just specify your sessionFactory
bean instead of getting it through the EMF)
最后你需要一个mbean服务器和导出器:
And finally you need an mbean server and exporter:
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
<property name="beans">
<map>
<entry key="yourkey:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" />
</map>
</property>
</bean>
这篇关于如何在Spring 3.0应用程序中配置Hibernate统计信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!