找不到CacheableOperation []缓存中名为“"的缓存 [英] Cannot find cache named '' for CacheableOperation[] caches

查看:652
本文介绍了找不到CacheableOperation []缓存中名为“"的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的错误是:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot find cache named 'getActionsBycasId' for CacheableOperation[public java.util.List com.codinko.database.DataBaseConnection.getActionsByCasId(int)] caches=[getActionsBycasId] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless=''
    at org.springframework.cache.interceptor.AbstractCacheResolver.resolveCaches(AbstractCacheResolver.java:81)
    at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:214)
    at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.<init>(CacheAspectSupport.java:553)
    at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:227)
    at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContexts.<init>(CacheAspectSupport.java:498)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:299)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
    at com.codinko.database.DataBaseConnection$$EnhancerBySpringCGLIB$$21a0d8a.getActionsByCasId(<generated>)
    at com.codinko.caching.EmployeeDAO.getActionBycasId(EmployeeDAO.java:47)
    at com.codinko.caching.EmployeeDAO$$FastClassBySpringCGLIB$$191aa49b.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:649)
    at com.codinko.caching.EmployeeDAO$$EnhancerBySpringCGLIB$$3399d753.getActionBycasId(<generated>)
    at com.codinko.caching.Main.main(Main.java:22)    

我的功能是:

@Cacheable("getActionsBycasId")
public List<SMSAction> getActionsByCasId(int casId){
    System.out.println("Inside getActionsByCasId");
    //My logic
    return list;
}    

当我在ehcache.xml上添加以下内容时,上述错误不会出现,但不知道为什么会出现此错误.

when i add below on ehcache.xml then above error not comes but can't know why this error come .

<cache name="getActionsBycasId" maxElementsInMemory="50" eternal="false"
    overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />    

即使我使用了annotation ????

Is this above configuration required in ehcache.xml file even though i used annotation ????

推荐答案

尝试一下:

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    List<Cache> caches = new ArrayList<Cache>();
    caches.add(new ConcurrentMapCache("getActionsBycasId"));
    cacheManager.setCaches(caches);
    return cacheManager;
}

这篇关于找不到CacheableOperation []缓存中名为“"的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆