
ehcache-spring-annotations - issue #76
Multiple config files with Spring context in multiple jars
Hello,
I don't know if my context is out of the box or typically as it is thinked by Ehcache and ehcache-spring-annotations.
I have multiple modules that build jar files.
In some modules, i have classes in which i added Cacheable annotation as defined on http://code.google.com/p/ehcache-spring-annotations/wiki/UsingCacheable
I would like to deal with each module cache configuration inside the module itself. That is to say : - @Cacheable on classes methods - Spring configuration inside the module (for exemple a spring xml file in src/main/resources/spring/ according the wild card i defined) - ehcache configuration file definining cache rules also inside the module
My files contain : Java: Code:
@Cacheable(cacheName="myMethodCache") public Object myMethod(String parameter) { ... }
Spring : Code:
<ehcache:annotation-driven cache-manager="mymodule1-cacheManager" />
<bean id="mymodule1-cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:mymodule-ehcache.xml"/> </bean>
ehcache config file (stored at the base of my jar file when built): Code:
<cache name="myMethodCache" eternal="false" maxElementsInMemory="1" overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0" timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU" />
I have another module that include my first module jar. This oher module has his own cache declaration using the same standard.
When i launch a job on the second module, i have this error : Code:
Caused by: com.googlecode.ehcache.annotations.CacheNotFoundException: Unable to find cache 'myModuleCache' at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getCache(CacheAttributeSourceImpl.java:223) at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.parseCacheableAnnotation(CacheAttributeSourceImpl.java:325) at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.findMethodAttribute(CacheAttributeSourceImpl.java:268) at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.computeMethodAttribute(CacheAttributeSourceImpl.java:242) at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:167) at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getAdviceType(CacheAttributeSourceImpl.java:122) at com.googlecode.ehcache.annotations.impl.CacheStaticMethodMatcherPointcut.matches(CacheStaticMethodMatcherPointcut.java:46) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:217) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254) at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1426) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ... 50 more
If i add the first module ehcache declaration in my second module, the error disappears. It seems that i have to add only one ehcache file in my context or maybe it is impossible to configure an ehcache context inside a jar file including in an application.
Could you help me or tell me what i did wrong ?
Thanks
Pierre
Comment #1
Posted on Jul 6, 2011 by Grumpy WombatI managed to do it.
The related post is here : http://forums.terracotta.org/forums/posts/list/5618.page#27960
The source code is here : http://itcb.svn.sourceforge.net/viewvc/itcb/addons/itcb-cache/trunk/
You can close the issue.
Comment #2
Posted on Jul 28, 2011 by Happy HippoWill ehcache-spring-annotations provide built-in support for multiple ehcache.xml files in various modules?
Comment #3
Posted on Jul 28, 2011 by Helpful DogIt is an interesting feature but right now all my spare development time is being spent working on the annotations portion of the JSR107 Caching Specification. So unfortunately unless someone can provide us a patch I don't foresee support within the next 3 months.
Comment #4
Posted on Aug 24, 2011 by Grumpy WombatIf this feature has to be implemented, it's in Spring directly, not in this module, i think.
If you use maven, you can add a dependency on itcb-cache as described in terracotta forum
Comment #5
Posted on Sep 20, 2011 by Helpful DogAs comment 4 states this is a Spring feature/deficiency issue, there is nothing this library can do about it.
Comment #6
Posted on Dec 28, 2011 by Helpful CamelWould the Cache Resolver be a possible solution here?
Comment #7
Posted on Jan 26, 2012 by Helpful CamelThought I would post a link to this question on Stackoverflow since it references the link Pierre posted.
http://stackoverflow.com/questions/8658789/using-spring-cache-annotation-in-multiple-modules
Status: Invalid
Labels:
Type-Defect
Priority-Medium