我努力配置hibernate jmx,以便通过hibernate jconsole插件获得一些指标。休眠jconsole弹簧配置
其实我也跟着从休眠状态的JConsole插件的官方网站的配置:http://hibernate-jcons.sourceforge.net/usage.html#pre-requisites
,但它不工作,所以我搜索互联网上几个小时,测试的东西。唯一相关的事情,我发现,与我的问题,就是:How to configure Hibernate statistics in Spring 3.0 application?
,但它仍然无法正常工作。我需要你的帮助。
这里是配置:
@PersistenceContext(unitName = DomainConstants.JPA_PU_BACKEND)
private EntityManager em;
@Bean(name="jmxExporter")
public MBeanExporter jmxExporter() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
MBeanExporter exporter = new MBeanExporter();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("Hibernate:application=Statistics", "hibernateStatisticsBean");
MBeanServerFactoryBean serverFactory = new MBeanServerFactoryBean();
serverFactory.setLocateExistingServerIfPossible(true);
// --- new1
MBeanServer MBeanServer = serverFactory.getObject();
exporter.setServer(MBeanServer);
exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
// end -- new1
exporter.setBeans(beans);
return exporter;
}
@Bean(name="hibernateStatisticsBean")
public StatisticsService hibernateStatisticsBean() {
StatisticsService service = new StatisticsService();
service.setStatisticsEnabled(true);
service.setSessionFactory(((Session)em.getDelegate()).getSessionFactory());
return service;
}
我还设置hibernate.generate_statistics为true,Hibernate配置。
我被卡住了。我真的需要这个工具来工作,因为我们的查询花费了很多时间。这个工具将是完美的。
编辑: 的的MBean似乎被加载。当我做查询时,属性会改变。 image2 http://imageshack.com/a/img838/5904/dj8c.png
但是,当我试图调用操作之一:getQueryStatistics,getCollectionStatistics等。我得到以下错误: image1 http://imageshack.com/a/img838/9693/ibkd.png
而实际上我不知道查询统计,没有任何显示: image3 http://imageshack.com/a/img835/8088/laoz.png
尝试直接设置的bean引用,而不是它的名字:'beans.put(“休眠:应用=统计” ,hibernateStatisticsBean())'。 –
谢谢安德烈的帮助。我试过你的解决方案,但它并没有改变任何东西。 –
当你说它不起作用时,这是什么意思? MBean不会显示在JMX中,您可以连接到JMX服务器等?你可以发布一些日志吗? –