2012-08-05 62 views
5

在我的追求,我的Grails应用程序进行个性化的Ehcache,我添加了以下XML来配置目录:异常的Grails应用程序定制ehcache.xml中抛出后

<?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> 

出乎我的意料,开始的时候,Grails的应用程序停止例外:

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 

任何提示?我正在使用grails 1.3.9;谢谢。

回答

8

与Spring有同样的问题,maxEntriesLocalHeapmaxEntriesLocalDisk抛出了相同的异常。什么似乎为我工作是使用maxElementsInMemorymaxElementsOnDisk来代替。从javadoc找到他们。

现在,基于他们被弃用,我认为有一个旧版本的EHCache继续我的conf,以及你的。

根据this table,maxEntriesLocalHeap出现在EHCache 2.5上。在此之前,它是maxElementsInMemory。当我遇到困难时,我使用了ehcache-spring-annotations,并且在撰写本文时,它是在1.2.0版本中,随ehcache 2.4.5一起提供 - 因此不支持这些属性。

经过纯弹簧配置和显式依赖到EHCache 2.5后,问题消失了,我可以使用我原本打算的属性。

3

在最新版本的Ehcache(2.6.x)中添加了像'maxEntriesLocalHeapEhcache'或内部元素作为'持久性'的标签。

我会去: A)使用'maxElementsInMemory'(而不是'maxEntriesLocalHeap');使用'overflowToDisk'和'diskPersistent'属性(而不是'persistence'元素),... B)尝试获取最新版本的插件或手动添加最新的jar到您的项目中。

+0

若要将旧属性与“persistence”元素进行比较,请参阅:http://www.ehcache.org/documentation/2.8/configuration/fast-restart.html#compatibility-with-previous-versions – 2016-03-15 08:22:29

0

如果你使用Hibernate

的版本4.3.5或4.3.7具有的Ehcache 2.4.7的依赖该版本不具备的特性maxEntriesLocalHeap和maxEntriesLocalDisk。

文档有关的Ehcache的2.4.x:http://ehcache.org/files/documentation/EhcacheUserGuide.pdf

使用我的例子冬眠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"/> 

0

正如EIS说,休眠-ehcache的内部使用ehcache 2.4.3,但属性不支持该版本。您需要使用更高版本的ehcache。

这里只是尝试添加更多的详细配置:

首先,添加两个休眠-的Ehcache和ehcache的核到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> 

然后,在弹簧配置中设置会话工厂的属性。使用org.hibernate中的类。 ,而不是从net.sf.ehcache。

<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory </prop> 
0

我遇到了类似的问题,我通过使用下面的罐子解决。

  1. ehcache.2.9.jar
  2. 的logback-核心1.0.13.jar
  3. 的logback经典-1.0.13.jar

您在项目路径中添加上述罐子。它会正常工作。

+0

请编辑您的回答一点 – 2017-08-29 05:47:35