由于某种原因,我无法将expiry元素添加到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 我没有看到标签有什么问题,任何人都有任何想法?
答案 0 :(得分:5)
Ehcache 3严格执行XSD,因此cache
或cache-template
中的元素必须按以下顺序排列:
key-type
value-type
expiry
eviction-advisor
loader-writer
listeners
resources
或heap
除了大小(地点7)之外,所有元素都是可选的,但在cache-template
中是可选的。
答案 1 :(得分:1)
您必须在xsi:schemaLocation
listeners
和expiry
配置
您的ehcache配置的正确形式如下:
<?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 :(得分:0)
这是对我有用的格式/示例(我从ehcache docs那里获得):
<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>