首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >echache3 XML解析问题

echache3 XML解析问题
EN

Stack Overflow用户
提问于 2017-05-24 17:34:17
回答 3查看 2.8K关注 0票数 4

由于某些原因,我无法将到期元素添加到ehcache3配置xml中。如果没有失效元素,它就能正常工作。

代码语言:javascript
复制
  <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>

错误信息是:

代码语言:javascript
复制
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,我没有发现标签有什么问题,有人知道吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-06-08 12:06:06

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

  1. key-type
  2. value-type
  3. expiry
  4. eviction-advisor
  5. loader-writer
  6. listeners
  7. resourcesheap
  8. 更多..。

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

票数 9
EN

Stack Overflow用户

发布于 2017-08-14 10:39:48

必须在xsi:schemaLocation之后添加listenersexpiry配置

ehcache配置的正确形式如下:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<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>
            <jsr107:cache name="people" template="heap-cache"/>
        </jsr107:defaults>
    </service>

    <!--thread-pools> 
        <thread-pool alias="defaultDiskPool" min-size="1" max-size="3"/>
    </thread-pools-->

    <!--disk-store thread-pool="defaultDiskPool" /-->

    <cache-template name="heap-cache">
        <expiry>
            <ttl unit="seconds">10</ttl>
        </expiry>
        <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>
        <resources>
            <heap unit="entries">2000</heap>
            <offheap unit="MB">100</offheap> <!-- unit of measure is case sensitive! -->
        </resources>

        <!--disk-store-settings thread-pool="defaultDiskPool" writer-concurrency="2" /-->

    </cache-template>
</config>
票数 2
EN

Stack Overflow用户

发布于 2019-03-06 07:24:53

这是对我有用的格式/示例(我是从ehcache文档获得的):

代码语言:javascript
复制
<ehcache:config xmlns:ehcache="http://www.ehcache.org/v3" xmlns:jcache="http://www.ehcache.org/v3/jsr107">
    <ehcache:cache alias="books">
        <ehcache:key-type>java.lang.String</ehcache:key-type>
        <ehcache:value-type>hello.Book</ehcache:value-type>
        <ehcache:resources>
            <ehcache:heap unit="MB">1</ehcache:heap>
            <!--ehcache:offheap unit="MB">10</ehcache:offheap-->
        </ehcache:resources>
    </ehcache:cache>
</ehcache:config>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44165149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档