Using Spring cache annotation in multiple modules

前端 未结 5 1959
小蘑菇
小蘑菇 2020-12-23 20:56

I have a util module that produces a jar to be used in other applications. I\'d like this module to use caching and would prefer to use Spring\'s annotation-driven

5条回答
  •  渐次进展
    2020-12-23 21:26

    In my Project I have been using ABC jar within XYZ war, both implementing ehCache with Spring 3.1,xml-driven configuration(we have ehCache.xml and then spring-context.xml where we are intercepting cache through Spring AOP in both the projects). And we are getting following error:

    java.lang.IllegalArgumentException: Cannot find cache named [xxxxxx] for CacheableOperation[] caches=[Cxxxxxxxx] | condition='' | key='#xxxxxxxxxxxxx' 
    at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:163) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.(CacheAspectSupport.java:443) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:173) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.cache.interceptor.CacheAspectSupport.createOperationContext(CacheAspectSupport.java:404) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:192) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
        at com.infy.flypp.dao.ContentDAO$$EnhancerByCGLIB$$9443481.getContentById() [cglib-2.2.2.jar:] 
    

    Solution:

    This is how we solved this issue:

    1. We copied all the cache configuration from ABCehCache.xml(from ABC jar) to XYZehCache.xml(from XYZ war).
    2. We deleted the ABCehCache.xml(from ABC jar) but all the configuration(like bean instantiation for ehCache.xml and Spring AOP) inside ABC-spring.xml will remain same.
    3. In XYZ-spring.xml, We imported ABC-spring.xml and defined composite cache manager.

    Supported Configuration files:

    ABC-spring.xml:

        
    
        
            
        
    
        
    

    XYZ-spring.xml:

    
    
    
        
        
            
                
                
            
        
        
    
    
        
        
    

提交回复
热议问题