如何在Spring 3.0应用程序中配置Hibernate统计信息? [英] How to configure Hibernate statistics in Spring 3.0 application?

查看:88
本文介绍了如何在Spring 3.0应用程序中配置Hibernate统计信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何进行配置,以便在基于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 persistence.xml 中或 hibernate.cfg.xml中 true / code>或者在你的会话工厂bean配置中)。然后注册这个bean:

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆