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 コンテキスト ファイルの 1 つにタグが必要です。この命令を含む (潜在的に推移的な) インポートされた構成ファイルがないことを再確認してください。

コメントへの返信:インポートされた xml ファイルを使用すると、確実にキャッシュ サポートが有効になります
<cache:annotation-driven/>インポートされた (および推移的にインポートされた) コンテキスト ファイルはすべて 1 つの単一の Spring コンテキストにマージされ、タグは Spring に、この命令が配置されている同じ xml ファイルで定義された Bean だけでなく、コンテキスト全体annotation-drivenで Bean の注釈を探すように指示します。理解しておくべき重要なことは、Bean 定義は物理的に複数のファイルに分割される可能性があることです (異なる jar から取得することもできます) が、コンテキストの論理的なモジュール化にはなりません。

このようなモジュール化は、コンテキスト間の親子関係を定義することによってのみ実現できます。この場合、親コンテキストが最初にロードされ、次に子コンテキストがロードされます (最初のコンテキストを親として指定します)。これにより、親コンテキストが基本的にその子を認識しないセットアップになりますが、子は親で定義された任意の Bean にアクセスできます。
これを使用して、最初に外部 jar で定義されたコンテキストをロードし、次に独自のコンテキストを子としてロードできます。このようにannotation-drivenして、親コンテキストの は Bean に影響を与えませんが、親コンテキストからは何にでもアクセスできます。
問題は、アプリケーションが Spring MVC webapp である場合、親コンテキストを宣言する簡単な方法がないことです。

于 2013-04-17T13:42:38.440 に答える