Java 如何在SpringXML文件上启用ehcache统计信息

Java 如何在SpringXML文件上启用ehcache统计信息,java,spring,ehcache,Java,Spring,Ehcache,基于以下配置,我无法在xml文件上启用ehcache统计信息。没有这样的属性来启用ehcache统计信息 <bean id="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property name="cacheName" value="diskCache"/> <property name="cacheManager" ref="cacheManager"/>

基于以下配置,我无法在xml文件上启用ehcache统计信息。没有这样的属性来启用ehcache统计信息

<bean id="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
  <property name="cacheName" value="diskCache"/>
  <property name="cacheManager" ref="cacheManager"/>
  <property name="maxElementsInMemory" value="1"/>
  <property name="overflowToDisk" value="true"/>
  <property name="maxElementsOnDisk" value="10"/>
</bean>

Ehcache 2.4.6带有禁用的缓存统计信息

<bean id="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
  <property name="cacheName" value="diskCache"/>
  <property name="cacheManager" ref="cacheManager"/>
  <property name="maxElementsInMemory" value="1"/>
  <property name="overflowToDisk" value="true"/>
  <property name="maxElementsOnDisk" value="10"/>
</bean>
还有其他人有过实施这一点的经验吗


在此方面的任何帮助或想法都将不胜感激

看起来内置的
EhCacheFactoryBean
不支持设置此标志(我建议您打开一个)。但是,您可以相对轻松地添加以下内容:

package com.example;

public class EhCacheWithStatisticsFactoryBean extends EhCacheFactoryBean {

    private boolean statisticsEnabled;

    @Override
    public void afterPropertiesSet() throws CacheException, IOException {
        super.afterPropertiesSet();
        getObject().setStatisticsEnabled(statisticsEnabled);
    }

    public void setStatisticsEnabled(boolean statisticsEnabled) {
        this.statisticsEnabled = statisticsEnabled;
    }
}
使用方法:

<bean id="cache" class="com.example.EhCacheWithStatisticsFactoryBean">
  <property name="cacheName" value="diskCache"/>
  <property name="cacheManager" ref="cacheManager"/>
  <property name="maxElementsInMemory" value="1"/>
  <property name="overflowToDisk" value="true"/>
  <property name="maxElementsOnDisk" value="10"/>
  <property name="statisticsEnabled" value="true"/> <!-- HERE -->
</bean>


当然,简单的方法是使用标准的
ehcache.xml
文件。

Spring3.1RC1将提供新功能