正在监视Ehcache统计信息



我正在使用Ehcache caching with spring配置。我需要监视jconsole mbeans或jvisualvm中的Ehcache对象,但我在jconsole下看不到ehcache mbeans。

我也在下面提到了statistics="true

。。。。。。。。。。

您可以尝试在代码中启用它。

CacheManager manager = CacheManager.getCacheManager("CacheName");
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true);

我们需要像下面的一样向托管beanserver注册ehcache

    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true" />
  </bean>
    <bean id="managementService"
        class="net.sf.ehcache.management.ManagementService"
        init-method="init"
        destroy-method="dispose">
        <constructor-arg ref="ehcache"/>
        <constructor-arg ref="mbeanServer"/>
        <constructor-arg index="2" value="true"/>
        <constructor-arg index="3" value="true"/>
        <constructor-arg index="4" value="true"/>
        <constructor-arg index="5" value="true"/>
 </bean>

您必须已经在spring-config-xml-中有以下条目

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
     <property name="cacheManager" ref="ehcache"/>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" scope="singleton">
    <property name="configLocation" value="classpath:ehcache.xml" />
    <property name="shared" value="true" />
</bean>

最新更新