2013-07-05 61 views
3

在项目中,我一直在使用ABC XYZ战争内罐子 XML配置,既实现的Ehcache与Spring 3.1,XML驱动的配置 (我们有ehCache.xml,然后在两个项目中通过Spring AOP拦截缓存的spring-context.xml)。而我们得到以下错误:春季3.1的Ehcache在罐子和战争,其中罐子将战争中使用:

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.<init>(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(<generated>) [cglib-2.2.2.jar:] 

回答

1

解决方案:

这就是我们解决了这个问题:

  1. 我们复制从ABCehCache.xml所有的缓存配置(从ABC JAR)到XYZehCache.xml(来自XYZ战争)。
  2. 我们删除了ABCehCache.xml(来自ABC jar),但ABC-spring.xml中的所有配置(如ehCache.xml和Spring AOP的bean实例化)将保持不变。
  3. XYZ-spring.xml中,我们导入ABC-spring.xml并定义了复合缓存管理器。

支持的配置文件:

ABC-spring.xml:

<aop:aspectj-autoproxy proxy-target-class="true" /> 

    <bean id="CacheManager1" class="org.springframework.cache.ehcache.EhCacheCacheManager"> 
     <property name="cacheManager" ref="ehcache"></property> 
    </bean> 

    <bean id="ehcache" 
     class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
     p:config-location="classpath:ABCEhcache.xml" /> 

XYZ-spring.xml:

<import resource="classpath*:ABC-spring.xml" /> 
<aop:aspectj-autoproxy proxy-target-class="true" /> 

    <bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager"> 
    <property name="cacheManagers"> 
     <array> 
      <ref bean="CacheManager1" /> 
      <ref bean="CacheManager2" /> 
     </array> 
    </property> 
    <property name="fallbackToNoOpCache" value="true" /> 
</bean> 

    <bean id="CacheManager2" class="org.springframework.cache.ehcache.EhCacheCacheManager" 
     p:cache-manager-ref="ehcache" /> 
    <bean id="ehcache" 
     class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
     p:config-location="classpath:XYZEhcache.xml" /> 

希望这将有助于!

相关问题