如何启用Ehcache 3.x JSR-107 MBean操作?

时间:2017-05-24 17:24:15

标签: java spring-boot ehcache jmx clear

为什么以下ehcache.xml不允许通过JMX清除缓存(在JVisualVM中为MBean禁用了Operations选项卡以进行缓存管理并启用缓存统计)?我使用spring boot框架并通过spring.cache.jcache.config属性指定ehcache.xml文件位置,并使用@Cachable spring框架注释。

<config
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'
    xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
    xsi:schemaLocation="
        http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
        http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">


  <service>
    <jsr107:defaults enable-management="true" enable-statistics="true"/> 
  </service>

  <cache alias="stringCache"> 
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
    <heap unit="entries">2000</heap>
  </cache>

</config>

1 个答案:

答案 0 :(得分:3)

JSR-107规范不支持清除缓存条目。只能清除统计信息。要解决这个问题,您必须创建自己的MBean。