Mon erreur est:
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)
Ma fonction est:
@Cacheable("getActionsBycasId")
public List<SMSAction> getActionsByCasId(int casId){
System.out.println("Inside getActionsByCasId");
//My logic
return list;
}
quand j'ajoute ci-dessous sur ehcache.xml alors l'erreur ci-dessus ne vient pas mais ne peut pas savoir pourquoi cette erreur vient.
<cache name="getActionsBycasId" maxElementsInMemory="50" eternal="false"
overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />
Est-ce que la configuration ci-dessus est requise dans le fichier ehcache.xml même si j’ai utilisé annotation
????
Essaye ça :
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
List<Cache> caches = new ArrayList<Cache>();
caches.add(new ConcurrentMapCache("getActionsBycasId"));
cacheManager.setCaches(caches);
return cacheManager;
}
Si vous utilisez spring cloud aws, désactivez la configuration automatique de élastique.
@EnableAutoConfiguration(exclude = ElastiCacheAutoConfiguration.class)
@EnableCaching
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication(exclude = {
ContextStackAutoConfiguration.class,
ElastiCacheAutoConfiguration.class
})
Juste être pointilleux, utilisez @SpringBootApplication au lieu de @EnableAutoConfiguration
Essayez de changer
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="cacheManagerName" value="cacheManager_service" />
<property name="configLocation" value="classpath:ehcache-services.xml" />
<property name="shared" value="true" />
</bean>
À
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" primary="true">
<property name="cacheManagerName" value="cacheManager_service" />
<property name="configLocation" value="classpath:ehcache-services.xml" />
</bean>
L'option d'exclusion ci-dessus, n'a pas fonctionné pour moi. Mais, ci-dessous a fonctionné. !! Si vous utilisez un printemps print, excluez l'élastique comme ci-dessous.
<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>