0

I am facing an issue wherein the code tries to find cache named "AdministrationContactManagerImpl.retrieve" but it fails to find it.The target method is annotated with @cacheable.

@Cacheable(value="administrationContactManagerImpl.retrieve", key="#prefix + #contract + #effectiveDate + #administrationRoles")
    public List<AdministrationContact> retrieve(Set<AdministrationRole> administrationRoles, Date effectiveDate,

I have not defined <ehcache:annotation-driven> in my main applicationContext file.This means that caching should not get enabled and I should not run in to the errors as output in the stacktrace. I suspect some jar's in the classpath might be enabling the caching but how it is enabled and how can I detect it?

Can anyone tell how could I disable the caching so that I can avoid this error.

We are using spring version 3.1.1.Release jars.

 java.lang.IllegalArgumentException: Cannot find cache named [administrationContactManagerImpl.retrieve] for CacheableOperation[public java.util.List com.principal.ris.contact.internal.impl.AdministrationContactManagerImpl.retrieve(java.util.Set,java.util.Date,java.lang.Integer,java.lang.String)] caches=[administrationContactManagerImpl.retrieve] | condition='' | key='#prefix + #contract + #effectiveDate + #administrationRoles'
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:163)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.<init>(CacheAspectSupport.java:443)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:173)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheAspectSupport.createOperationContext(CacheAspectSupport.java:404)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:192)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at com.principal.ris.contact.internal.impl.AdministrationContactManagerImpl$$EnhancerByCGLIB$$ddaad355.retrieve(<generated>)
[4/17/13 14:44:50:001 IST] 0000001a SystemErr     R     at com.principal.ris.tpaview.listener.TpaViewUserTemplateListener.contextCreated(TpaViewUserTemplateListener.java:118)

Updating this post : I have selected the answer as best answer but I will tell you all what I did. In you java maven projects, you really do not need to include such annotations which can impact your context. As a best practice, always keep the switches configurations in your war's pom file.

4

1 回答 1

1

参考文档的这一部分详细介绍了如何在 Spring 中启用对缓存注释的支持。基于此,<cache:annotation-driven/>您的 xml 上下文文件之一中必须有一个标签。仔细检查是否没有(可能是可传递的)导入的包含此指令的配置文件。

回复您的评论:
<cache:annotation-driven/>导入的 xml 文件中肯定会启用缓存支持。所有导入(和传递导入)的上下文文件都合并到一个 Spring 上下文中,并且该标记指示 Spring 在整个上下文annotation-driven中查找 beans 上的注释,而不仅仅是在放置该指令的同一 xml 文件中定义的 beans 上。要理解的重要一点是,bean 定义可能在物理上被分成几个文件(也可以来自不同的 jar),但这不会导致上下文的任何逻辑模块化。

这种模块化只能通过定义上下文之间的父子关系来实现,其中首先加载父上下文,然后再加载子上下文(将第一个指定为其父上下文)。这导致父上下文基本上不知道其子上下文的设置,但子上下文可以访问其父上下文中定义的任何 bean。
您可以使用它首先加载外部 jar 中定义的上下文,然后将您自己的上下文作为子项加载。这样annotation-driven,父上下文中的 bean 不会影响您的 bean,而您仍然可以从父上下文中访问任何内容。
问题是如果您的应用程序是 Spring MVC webapp,则没有简单的方法来声明父上下文。

于 2013-04-17T13:42:38.440 回答