使用JMX和Jconsole监视Ehcache中的缓存日期

时间:2018-10-22 05:41:45

标签: spring caching ehcache jmx

我正在使用JMX方法可视化在Spring Web项目中使用Ehcache存储的缓存数据。每当我在Jconsole中单击getCache()方法时,都会收到以下错误。有人可以帮我吗?预先感谢

clicking on getCache() with the cache name as param

error message

配置文件:

@Configuration
@EnableCaching
public class SpringCachePocConfig implements CachingConfigurer {

    net.sf.ehcache.CacheManager newCacheManager;

    @Bean(destroyMethod = "shutdown")
    public net.sf.ehcache.CacheManager ehCacheManager() {
        //Construct you cache here.

        net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
        config.addCache(<Your cache>);

        this.newCacheManager = new net.sf.ehcache.CacheManager(config);
        return newCacheManager;
    }


    @Bean
    public ManagementService managementService() {
        return new ManagementService(ehCacheManager(), mbeanServer(), true, true, true, true);

    }


    @Bean
    @Override
    public CacheManager cacheManager() {
        return new EhCacheCacheManager(ehCacheManager());
    }


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

    @PostConstruct
    public void init() {
        ManagementService.registerMBeans(ehCacheManager(), mbeanServer(), true, true, true, true);
    }


}

1 个答案:

答案 0 :(得分:1)

您必须在jconsole.exe -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;<<ehcache.jar>>之类的jconsole类路径上添加ehcache jar文件(及其支持的jar文件,如果有的话)。从工具-JConsole

调用此类操作时,这将解决java.rmi.UnmarshalException