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

How to enable Ehcache 3.x JSR-107 MBean operations?

为什么以下 ehcache.xml 不允许通过 JMX 清除缓存(操作选项卡在 JVisualVM for MBean 中禁用以进行缓存管理并启用缓存统计)?我使用 spring 引导框架并通过 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>

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