xml - echache3 XML 解析问题

标签 xml ehcache-3

出于某种原因,我无法将到期元素添加到 ehcache3 配置 xml 中。 没有到期元素,它工作正常。

  <config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'
    xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>

  <service>
    <jsr107:defaults>
      <jsr107:cache name="people" template="heap-cache"/>
    </jsr107:defaults>
  </service>

  <cache-template name="heap-cache">
    <listeners>
        <listener>
          <class>org.terracotta.ehcache.EventLogger</class>
          <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
          <event-ordering-mode>UNORDERED</event-ordering-mode>
          <events-to-fire-on>CREATED</events-to-fire-on>
          <events-to-fire-on>UPDATED</events-to-fire-on>
          <events-to-fire-on>EXPIRED</events-to-fire-on>
          <events-to-fire-on>REMOVED</events-to-fire-on>
          <events-to-fire-on>EVICTED</events-to-fire-on>
        </listener>
    </listeners>
     <expiry>
        <ttl unit="seconds">10</ttl>
    </expiry>
    <resources>
      <heap unit="entries">2000</heap>
      <offheap unit="MB">100</offheap> <!-- unit of measure is case sensitive! -->
    </resources>
  </cache-template>
</config>

错误信息是:

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'expiry'. One of '{"http://www.ehcache.org/v3":heap, "http://www.ehcache.org/v3":resources, "http://www.ehcache.org/v3":heap-store-settings, "http://www.ehcache.org/v3":disk-store-settings, "http://www.ehcache.org/v3":service-configuration}' is expected.

但是看看这个 xsd: http://www.ehcache.org/schema/ehcache-core.xsd 我没有看到标签有任何问题,有人知道吗?

最佳答案

Ehcache 3 严格执行 XSD,因此 cachecache-template 中的元素必须按以下顺序排列:

  1. 键类型
  2. 值类型
  3. 到期
  4. 驱逐顾问
  5. loader-writer
  6. 监听器
  7. 资源
  8. 更多...

除了在 cache-template 中可选的大小(位置 7)之外,所有元素都是可选的。

关于xml - echache3 XML 解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44165149/

相关文章:

java - ehcache3 - 为什么缓存不会过期?

spring - 第三方Spring库中的缓存管理器

xml - 文档中的多个 XML 声明是否为格式正确的 XML?

php - Xpath查询结果始终为空

python - 防止 ElementTree 为每个元素添加命名空间

java - 在没有 XML 配置的情况下将 Ehcache CacheManager (v 3.x) 转换为 Spring CacheManager

hibernate - java.lang.annotation.IncompleteAnnotationException : org. terracotta.statistics.Statistic 缺失元素类型

Java EHCache 3 监听器和元空间问题

c# - Office 加载项功能区 : same tab with 2 addins

php - 如何使用 PHP 将已解析的 XML 传递到 mySQL 数据库中?