2015-01-19 11 views
11

Mój błąd jest:Nie można znaleźć cache o nazwie '' dla CacheableOperation [] skrytek

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)  

Moja funkcja to:

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

kiedy dodać poniżej na ehcache.xml następnie powyżej błędu nie przychodzi, ale nie wiem, dlaczego ten błąd się pojawia.

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

Czy to powyżej konfiguracja wymagane w pliku ehcache.xml chociaż użyłem annotation ????

+6

Chodzi o to, że używasz adnotacji @Cacheable, aby poinstruować Spring, aby buforowała wynik w pamięci podręcznej o nazwie "getActionsBycasId". Jednak dopóki nie skonfigurujesz tej pamięci podręcznej za pomocą pliku konfiguracyjnego Ehcache, nie masz pamięci podręcznej o nazwie "getActionsBycasId". –

Odpowiedz

4

Spróbuj tego:

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

Jeśli używasz wiosenne chmurze AWS wyłączyć automatyczną konfigurację elasticache.

@EnableAutoConfiguration(exclude = ElastiCacheAutoConfiguration.class) 
@EnableCaching 
@SpringBootApplication 
public class Application { 
    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 
} 
+0

Dzięki, że rozwiązałem mój problem. To dziwne, że ten problem nie występuje, jeśli moja aplikacja działa w lokalnej skrzynce, ale dzieje się tylko wtedy, gdy aplikacja jest wdrożona w EC2. – kca2ply

3
@SpringBootApplication(exclude = { 
     ContextStackAutoConfiguration.class, 
     ElastiCacheAutoConfiguration.class 
}) 

Tylko będąc Użyj nit-wybredna @SpringBootApplication zamiast @EnableAutoConfiguration

0

Powyższy wykluczyć opcji, nie działał na mnie. Ale poniżej działało. !! Jeśli używasz chmurki spring aws, to wyklucz sprężynę jak poniżej.

<dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-aws-messaging</artifactId> 
      <exclusions> 
       <exclusion> 
        <groupId>com.amazonaws</groupId> 
        <artifactId> 
         elasticache-java-cluster-client 
        </artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
Powiązane problemy