2012-09-07 54 views
0
CacheManager的初始化错误

我在谷歌应用程序引擎V1.7.0使用的EHCache 2.6.0编程方式(没有ehcache.xml中)。GAE上的EHCache

当我实例的CacheManager使用:

CacheManager cacheManager = CacheManager.create(); 

我得到错误:

Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers) 
    at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:217) 
    at java.util.concurrent.atomic.AtomicRefe...(length 9029) 

我想:

CacheManager cacheManager = new CacheManager(); 

,并与监测关:

Configuration configuration = new Configuration(); 
configuration.setMonitoring(Configuration.Monitoring.OFF.name()); 
configuration.setUpdateCheck(false); 
CacheManager cacheManager = new CacheManager(configuration); 

为他们两个我有以下错误:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.ehcache.util.lang.VicariousThreadLocal 
    at net.sf.ehcache.TransactionController.<init>(TransactionController.java:43) 
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:433) 
    at net.sf.ehcache.CacheManager.init(CacheManager.java:374) 

如何解决这个问题?

回答

1

应用服务引擎是一种分布式系统,其中请求被自动多个前端实例处理。在这样的设置,你不能使用在前端实例缓存实现(的EHCache),因为你将有运行的EHCache的多个实例,写一个的EHCache不会对其他EHCaches反映。

相反,你应该使用AppEngine上自己的memcache service

+0

但提供的EHCache GAE支持,请参阅[链接](http://ehcache.org/documentation/integrations/googleappengine) –

+0

OK,在这种情况下,它似乎的EHCache包装GAE缓存。但是,你需要适当的配置:http://ehcache.org/documentation/integrations/googleappengine#configuring-ehcachexml –

+0

“兼容性 的Ehcache是​​兼容的,与谷歌应用程序引擎谷歌App Engine提供一个约束的运行制约网络工程,线程和文件系统访问“。 。网络限制意味着它不会被分发。如果我错了,请纠正我! –

3

在我看来,那的Ehcache V2.6是与当前的AppEngine兼容。我不得不切换到以前版本的ehcache才能运行。经过漫长的尝试和错误2.4.7版本似乎是稳定的。 '显然'由ehcache提供的配置不起作用。这里是我不得不对其进行配置:

<?xml version="1.0" encoding="UTF-8"?> 
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" > 
    <cacheManagerEventListenerFactory class="" properties=""/> 
    <defaultCache 
     maxElementsInMemory="10000" 
     eternal="false" 
     overflowToDisk="false" 
     timeToIdleSeconds="120" 
     timeToLiveSeconds="120" 
     memoryStoreEvictionPolicy="LRU"> 
    </defaultCache> 
<!--Example sample cache--> 
    <cache name="sid" 
     maxElementsInMemory="100" 
     eternal="false" 
     timeToIdleSeconds="300" 
     timeToLiveSeconds="300" 
     memoryStoreEvictionPolicy="LFU" 
     /> 
</ehcache>