Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception thrown after customizing ehcache.xml in grails application

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.

like image 363
xain Avatar asked Aug 05 '12 13:08

xain


2 Answers

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.

like image 138
eis Avatar answered Nov 11 '22 22:11

eis


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.

like image 39
mrod Avatar answered Nov 11 '22 23:11

mrod