我的错误是:
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上添加以下内容时,上面的错误不会出现,但不知道为什么会出现此错误。
<cache name="getActionsBycasId" maxElementsInMemory="50" eternal="false"
overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />
即使我使用了annotation
,ehcache.xml文件中是否需要上述配置?
9条答案
按热度按时间y4ekin9u1#
试试看:
hm2xizp92#
如果使用spring cloud aws,请禁用自动弹性缓存配置。
pvcm50d13#
只是吹毛求疵,使用**@SpringBootApplication而不是@启用自动配置**
v440hwme4#
试试换
结束日期
wribegjk5#
您可以在resources文件夹中定义ehcache.xml,并考虑配置、、标记和设置别名作为您的缓存方法。
w80xi6nr6#
添加ehcache.xml
更新您的application.properties
cld4siwp7#
由于类路径资源中的
ehcache.xml
文件已经具有配置,因此最好的方法是使用此文件配置初始化Bean:pgky5nke8#
只需在单元测试的配置中创建一个如下所示的@Bean:
n3h0vuf29#
上面的排除选项,对我不起作用。但是,下面的起作用了。!!如果你使用的是Spring aws cloud,那么就像下面一样排除弹性。