2015-01-19 5 views
11

मेरे त्रुटि है: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 पर नीचे जोड़ने लेकिन नहीं आता पता नहीं क्यों यह त्रुटि आती है।

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

इस ऊपर विन्यास ehcache.xml फ़ाइल में आवश्यक है, भले ही मैं annotation इस्तेमाल किया ????

+6

बिंदु यह है कि आप "getActionsBycasId" नामक कैश में परिणाम को कैश करने के लिए स्प्रिंग को निर्देशित करने के लिए @ कैशेबल एनोटेशन का उपयोग करते हैं। हालांकि, जब तक आप इस कैश को Ehcache कॉन्फ़िगरेशन फ़ाइल के माध्यम से कॉन्फ़िगर नहीं करते हैं, तब तक आपके पास "getActionsBycasId" नामक कैश नहीं है। –

उत्तर

4

इस प्रयास करें:

@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

आप वसंत बादल एडब्ल्यूएस का उपयोग करते हैं, स्वत: elasticache विन्यास को अक्षम करें।

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

धन्यवाद कि मेरी समस्या हल हो गई। यह अजीब बात है कि यह समस्या तब नहीं होती है जब मेरा एप्लिकेशन स्थानीय बॉक्स पर चलता है लेकिन केवल तभी होता है जब एप्लिकेशन ईसी 2 पर तैनात किया जाता है। – kca2ply

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

बस लीख picky उपयोग किया जा रहा है @SpringBootApplication बजाय@EnableAutoConfiguration

0

ऊपर मेरे लिए बाहर निकालने के विकल्प, फ्लॉप काम। लेकिन, नीचे काम किया। !! यदि आप वसंत aws क्लाउड का उपयोग कर रहे हैं, तो नीचे की तरह लोचदार बाहर निकालें।

<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> 
संबंधित मुद्दे