scwanglijun / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 1 forks source link

Multiple config files with Spring context in multiple jars #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by pile...@gmail.com on 24 Jun 2011 at 6:48

GoogleCodeExporter commented 9 years ago
I 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.

Original comment by pile...@gmail.com on 6 Jul 2011 at 12:43

GoogleCodeExporter commented 9 years ago
Will ehcache-spring-annotations provide built-in support for multiple 
ehcache.xml files in various modules?

Original comment by james.eliyezar@gmail.com on 28 Jul 2011 at 2:22

GoogleCodeExporter commented 9 years ago
It 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. 

Original comment by eric.dalquist on 28 Jul 2011 at 2:32

GoogleCodeExporter commented 9 years ago
If 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

Original comment by pile...@gmail.com on 24 Aug 2011 at 3:27

GoogleCodeExporter commented 9 years ago
As comment 4 states this is a Spring feature/deficiency issue, there is nothing 
this library can do about it.

Original comment by eric.dalquist on 20 Sep 2011 at 1:56

GoogleCodeExporter commented 9 years ago
Would the Cache Resolver be a possible solution here?

Original comment by sne...@gmail.com on 28 Dec 2011 at 12:12

GoogleCodeExporter commented 9 years ago
Thought 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-mult
iple-modules

Original comment by sne...@gmail.com on 26 Jan 2012 at 1:52