我面临一个问题,其中代码尝试查找名为“AdministrationContactManagerImpl.retrieve”的缓存,但无法找到它 . 目标方法使用@cacheable注释 .
@Cacheable(value="administrationContactManagerImpl.retrieve", key="#prefix + #contract + #effectiveDate + #administrationRoles")
public List<AdministrationContact> retrieve(Set<AdministrationRole> administrationRoles, Date effectiveDate,
我没有在我的主applicationContext文件中定义 <ehcache:annotation-driven>
. 这意味着不应该启用缓存,我不应该在堆栈跟踪中作为输出运行错误 . 我怀疑类路径中的某些jar可能启用了缓存但是如何启用它以及如何检测它?
任何人都可以告诉我如何禁用缓存,以便我可以避免此错误 .
我们使用的是Spring 3.1.1版 . 发布 jar .
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)
更新这篇文章:我选择了答案作为最佳答案,但我会告诉你我所做的一切 . 在java maven项目中,您实际上不需要包含可能影响您的上下文的注释 . 作为最佳实践,请始终将交换机配置保留在war的pom文件中 .
1 回答
This section参考文档提供了有关如何在Spring中启用对缓存注释的支持的详细信息 . 基于此,您的一个xml上下文文件中必须有一个
<cache:annotation-driven/>
标记 . 仔细检查是否没有(可能传递)导入的包含此指令的配置文件 .Reply to your comment:
在导入的xml文件中使用
<cache:annotation-driven/>
肯定会启用缓存支持 . 所有导入(和传递导入)的上下文文件都合并到一个Spring上下文中,annotation-driven
标记指示Spring在整个上下文中查找bean上的注释,而不仅仅是在放置此指令的同一xml文件中定义的bean上 . 需要理解的重要一点是,bean的定义可能会被划分为几个文件(也可能来自不同的jar),但这不会导致上下文的任何逻辑模块化 .这种模块化只能通过定义上下文之间的父子关系来实现,其中首先加载父上下文,然后加载子上下文(将第一个指定为其父项) . 这导致父上下文基本上不知道其子节点的设置,但子节点可以访问其父节点中定义的任何bean .
您可以使用它来首先加载外部jar中定义的上下文,然后将您自己的上下文作为子项加载 . 这样,父上下文中的
annotation-driven
不会影响您的bean,而您仍然可以从partent上下文访问任何内容 .问题是,如果您的应用程序是Spring MVC webapp,则没有简单的方法来声明父上下文 .