Closed GoogleCodeExporter closed 9 years ago
If you declare the CacheKeyGenerator bean explicitly in your spring app context
you can wire in the SimpleReflectionHelper explicitly and then in your
@Cacheable annotation reference the bean name for the key generator name or in
the ehcache:annnotation-driven element specify that generator as the default
generator.
Also the code shouldn't spin up that Thread unless you're actually using
reflection for key generation so another option is to not use reflection.
Also note that using SimpleReflectionHelper instead of CachingReflectionHelper
will have a pretty significant performance impact since every cached invocation
will require all reflection operations.
If would be interesting if there is a system property that can be used to
detect that the code is running in GAE and have a
GoogleAppEngineReflectionHelper that cached lookups but didn't bother with weak
reference cleanup since I don't think you can run into the same Class reference
leak there as you can in standard servlet containers on webapp reload.
Original comment by eric.dalquist
on 11 Dec 2010 at 6:00
I had the following setup:
<bean id="reflectionHelper"
class="com.googlecode.ehcache.annotations.key.SimpleReflectionHelper" />
<bean id="defaultCacheKeyGenerator"
class="com.googlecode.ehcache.annotations.key.HashCodeCacheKeyGenerator">
<property name="reflectionHelper" ref="reflectionHelper"/>
</bean>
<ehcache:annotation-driven
default-cache-key-generator="defaultCacheKeyGenerator"/>
But it already fails on GAE when loading the application context when it is
trying to create a new instance of CachingReflectionHelper. An extract from the
log:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name
'com.googlecode.ehcache.annotations.config.internalEhCacheCachingAdvisor':
Cannot resolve reference to bean
'com.googlecode.ehcache.annotations.impl.CacheStaticMethodMatcherPointcut#0'
while setting bean property 'pointcut'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name
'com.googlecode.ehcache.annotations.impl.CacheStaticMethodMatcherPointcut#0':
Cannot resolve reference to bean
'com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl#0' while
setting bean property 'cacheAttributeSource'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl#0':
Cannot resolve reference to bean
'com.googlecode.ehcache.annotations.key.CachingReflectionHelper' while setting
bean property 'reflectionHelper'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.googlecode.ehcache.annotations.key.CachingReflectionHelper':
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.googlecode.ehcache.annotations.key.CachingReflectionHelper]:
Constructor threw exception; nested exception is
java.security.AccessControlException: access denied
(java.lang.RuntimePermission modifyThreadGroup):
java.security.AccessControlException: access denied
(java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)
at java.security.AccessController.checkPermission(AccessController.java:567)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:304)
at java.lang.Thread.init(Thread.java:349)
at java.lang.Thread.<init>(Thread.java:436)
at com.googlecode.ehcache.annotations.key.CachingReflectionHelper$1.<init>(CachingReflectionHelper.java:61)
at com.googlecode.ehcache.annotations.key.CachingReflectionHelper.<init>(CachingReflectionHelper.java:61)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:33)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:71)
I assume that this caused in the class
AnnotationDrivenEhCacheBeanDefinitionParser?
When I replace the CachingReflectionHelper.class argument with
SimpleReflectionHelper.class in the method setupCachingReflectionHelper of the
AnnotationDrivenEhCacheBeanDefinitionParser class, then it is working just
fine. Probably an instance is created even when not needed?
Original comment by peter.ku...@gmail.com
on 11 Dec 2010 at 7:54
This should be resolved on the next version of the library. We're switching
from some cribbed Google Guice code to Google Guava. I would assume that Guava
will run correctly on GAE.
Original comment by eric.dalquist
on 19 Apr 2011 at 9:31
Would you mind of informing the scheduled release date of either version 1.2 or
2.0 with this fix?
I would like to know it because I have also hit this AccessControlException
exception as posted at
http://forums.terracotta.org/forums/posts/list/0/5943.page#30552.
Thank you.
Original comment by art...@gmail.com
on 12 Sep 2011 at 7:07
I get BeanCreationException when I enable ehcache and deploy my spring project
to GAE.
#####################
I have the ehcache setting as below :
<ehcache:annotation-driven
proxy-target-class="true" cache-manager="ehCacheManager" self-populating-cache-scope="method" />
<bean id="ehCacheManager" lazy-init="false"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xml</value>
</property>
<property name="shared" value="false" />
</bean>
#####################
and ehcache.xml as below :
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false">
<cacheManagerEventListenerFactory
class="" properties="" />
<defaultCache maxElementsInMemory="100" eternal="true"
timeToIdleSeconds="0" timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU">
<persistence strategy="none" />
</defaultCache>
<cache name="memCache" maxElementsInMemory="100" eternal="true"
memoryStoreEvictionPolicy="LRU">
</cache>
</ehcache>
#####################
I get the GAE log message as below :
INFO: Pre-instantiating singletons in ...
INFO: Initializing EhCache CacheManager
INFO: Destroying singletons in ...
ERROR: Context initialization
failedorg.springframework.beans.factory.BeanCreationException: Error creating
bean with name ...
#####################
If I don't enable ehcache,the message show only "INFO: Pre-instantiating
singletons in ..." but not "INFO: Destroying singletons in ..."
The project enable ehcache and caching function work fine in the local server.
What is the correct setting for ehcache with spring on GAE ? Thanks.
Original comment by thinlen2...@gmail.com
on 17 Aug 2013 at 8:06
Original issue reported on code.google.com by
peter.ku...@gmail.com
on 11 Dec 2010 at 8:24