Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ehcache does not allow persistence element

Tags:

spring

ehcache

I am using Ehcache Version 2.7

pom.xml

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.7.0</version>
</dependency>

context-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" />

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>

I am getting the following Exception

org.xml.sax.SAXException: null:9: Element <cache> does not allow nested <persistence> elements.

Even though it is allowed in http://ehcache.org/ehcache.xsd

<xs:element minOccurs="0" maxOccurs="1" ref="persistence"/>

I am not getting what can cause that issue and why SAX complains about persistence not allowed. What am I doing wrong?

like image 841
MatthiasLaug Avatar asked Sep 15 '26 17:09

MatthiasLaug


1 Answers

It turned out that I had hibernate ehcache loaded in my pom.xml which conflicts with ehcache 2.7.0. After I removed that dependency, everything worked fine. Another 4 hours worth fully spend :(

like image 186
MatthiasLaug Avatar answered Sep 17 '26 08:09

MatthiasLaug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!