Exception thrown after customizing ehcache.xml in grails application
Asked Answered
I

5

8

In my quest to personalize ehcache in my grails app, I added the following xml to the config directory:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" >
<diskStore path="/path/to/store/data"/>
<cacheManagerEventListenerFactory class="" properties=""/>
<defaultCache
   maxEntriesLocalHeap="10000"
   eternal="false"
   timeToLiveSeconds="120">
   <persistence strategy="none"/>
</defaultCache>
<cache name="Book"
  maxEntriesLocalHeap="10000"
  timeToIdleSeconds="300"
   />
<cache name="org.hibernate.cache.UpdateTimestampsCache"
  maxEntriesLocalHeap="10000"
  timeToIdleSeconds="300"
   />
<cache name="org.hibernate.cache.StandardQueryCache"
  maxEntriesLocalHeap="10000"
  timeToIdleSeconds="300"
   />
</ehcache>

To my surprise, when started, the grails app stops with the exception:

Caused by: net.sf.ehcache.CacheException: Error configuring from input stream. Initial  cause was null:9: Element <defaultCache> does not allow attribute "maxEntriesLocalHeap".
at    net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:99)
... 30 more

Any hints ? I'm using grails 1.3.9; thanks.

Indies answered 5/8, 2012 at 13:3 Comment(0)
H
9

Got the same problem with Spring, maxEntriesLocalHeap and maxEntriesLocalDisk threw the same exception. What seemed to work for me was using maxElementsInMemory and maxElementsOnDisk instead. Found them from javadoc.

Now, based on them being deprecated, I assume there was an older version of EHCache going on with my conf, as well as yours.

Based on this table, maxEntriesLocalHeap came on EHCache 2.5. Before that it was maxElementsInMemory. When I had trouble, I had used ehcache-spring-annotations, and as of this writing it is on version 1.2.0, coming with ehcache 2.4.5 - thus not supporting these properties.

After going for pure Spring config and explicit dependency to EHCache 2.5, problem went away and I was able to use the properties I originally intended to.

Humor answered 3/10, 2012 at 13:30 Comment(0)
L
3

Tags like 'maxEntriesLocalHeapEhcache' or inner elements as 'persistence' have been added in the most recent version of Ehcache (2.6.x).

I'd go for: A) Use 'maxElementsInMemory' (instead of 'maxEntriesLocalHeap'); use 'overflowToDisk' and 'diskPersistent' attributes (instead of the 'persistence' element), ... B) Try to get the latest version of the plugin or add the latest jars manually to your project.

Lenorelenox answered 16/10, 2012 at 10:41 Comment(1)
To compare the old properties to the persistence element, see: ehcache.org/documentation/2.8/configuration/…Boarding
C
1

If you to use Hibernate

The versions 4.3.5 or 4.3.7 have a dependency of Ehcache 2.4.7 that version don't have the properties maxEntriesLocalHeap and maxEntriesLocalDisk .

Documentation about Ehcache 2.4.x: http://ehcache.org/files/documentation/EhcacheUserGuide.pdf

My example using hibernate 4.3.5:

<defaultCache maxElementsInMemory="10000"
              eternal="false"
              timeToIdleSeconds="300"
              timeToLiveSeconds="600"
              diskSpoolBufferSizeMB="30"
              maxElementsOnDisk="10000"
              diskExpiryThreadIntervalSeconds="120"
              memoryStoreEvictionPolicy="LRU" statistics="false">
</defaultCache>

<cache
        name="org.hibernate.cache.spi.UpdateTimestampsCache"
        maxElementsInMemory="10000"
        eternal="false">
</cache>

<cache
        name="org.hibernate.cache.internal.StandardQueryCache"
        maxElementsInMemory="10000"
        eternal="false"
        timeToLiveSeconds="300">
</cache>

<!--
If you are concerned about cpu utilisation and locking in the DiskStore, you can set the
diskExpiryThreadIntervalSeconds to a high number - say 1 day. Or you can effectively turn it off by
setting the diskExpiryThreadIntervalSeconds to a very large value
-->
<cache
        name="br.com.atlantico.toi.model.calc.Anomalia"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"/>

Centiliter answered 19/12, 2014 at 0:32 Comment(0)
P
0

Just as eis said, Hibernate-ehcache internally use ehcache 2.4.3, but attribute not support on that verion. You need to use a higher version of ehcache.

Here just try to add more detailed configurations :

Firstly,add both hibernate-ehcache and ehcache-core to maven pom.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.6.5</version>
</dependency>

Then, set property for session factory in your spring configuration. Use classes from org.hibernate., instead of from net.sf.ehcache.

<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory </prop>
Pint answered 20/5, 2015 at 3:15 Comment(0)
A
0

I have faced the similar issue and I resolved by using the following jars.

  1. ehcache.2.9.jar
  2. logback-core-1.0.13.jar
  3. logback-classic-1.0.13.jar

you add above jars in your project path.. it will work fine.

Audacious answered 29/8, 2017 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.