Ehcache不允许持久性元素

Mat*_*aug 2 spring ehcache

我使用的是Ehcache 2.7版

的pom.xml

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.7.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

上下文cache.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/cache 
    http://www.springframework.org/schema/cache/spring-cache.xsd">

<!-- generic cache manager -->
<cache:annotation-driven />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
 p:cacheManager-ref="ehcache"/>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:configLocation="classpath:ehcache.xml" p:shared="true" />
Run Code Online (Sandbox Code Playgroud)

ehcache.xml中

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">   

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
    <cache name="AC" maxElementsInMemory="50000" eternal="true" overflowToDisk="false">
        <persistence strategy="localRestartable" synchronousWrites="false" />
    </cache>

</ehcache>
Run Code Online (Sandbox Code Playgroud)

我得到以下例外

org.xml.sax.SAXException: null:9: Element <cache> does not allow nested <persistence> elements.
Run Code Online (Sandbox Code Playgroud)

即使允许进入 http://ehcache.org/ehcache.xsd

<xs:element minOccurs="0" maxOccurs="1" ref="persistence"/>
Run Code Online (Sandbox Code Playgroud)

我没有得到导致该问题的原因以及为什么SAX抱怨persistence不允许.我究竟做错了什么?

Mat*_*aug 8

事实证明我在我的pom.xml中加载了hibernate ehcache,它与ehcache 2.7.0冲突.我删除了依赖后,一切正常.另外4小时值得完全消费:(

  • 我刚刚加入了您的“ 4小时值得花的钱”俱乐部。仍然会在2018年发生...。 (2认同)