Monitoring Ehcache via JMX

五迷三道 提交于 2020-01-07 06:39:11

问题


I have implemented application in Spring + Hibernate. To optimize ORM operations I have followed by this tutorial to enable monitoring for Ehcache:

@EnableWebMvc
@EnableSpringDataWebSupport
@EnableCaching
...
public class SpringWebConfig extends WebMvcConfigurerAdapter {

    ....

    @Bean
    public EhCacheCacheManager ehCacheManager() {
        EhCacheCacheManager cacheManager = new EhCacheCacheManager();
        cacheManager.setCacheManager((net.sf.ehcache.CacheManager) ehCacheManagerFactory().getObject());

        return cacheManager;
    }

    @Bean
    public EhCacheManagerFactoryBean ehCacheManagerFactory() {
        EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
        cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
        cmfb.setShared(true);
        return cmfb;
    }

    @Bean
    public ManagementService managementService() {
        return new ManagementService(ehCacheManager().getCacheManager(), mBeanServer(), true, true, true, true);
    }


    @Bean
    public MBeanServer mBeanServer() {
        MBeanServer bean = ManagementFactory.getPlatformMBeanServer();
        return bean;
    }
}

However I cannot see any ehache beans in jConsole:

Do you know if I missed something to enable statistics?


回答1:


The issue comes from the fact that you are simply creating the ManagementService but not initialising it.

Your managementService method needs to invoke the init() method on the created ManagementService.

Unless you effectively need access to the ManagementService for other purposes, exposing it as a bean is not required and you may replace this by a usage of the static ManagementService.registerMBeans(CacheManager, MBeanServer, boolean, boolean, boolean, boolean) either inside the ehCacheManagerFactory() or ehCacheManager() methods.

The static method creates the ManagementService and initialises it.



来源:https://stackoverflow.com/questions/40449809/monitoring-ehcache-via-jmx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!