I am trying to use jcache with hazelcast server provider. But getting this exception.
java.lang.IllegalArgumentException: Cannot find cache named 'xyzCache' for Builder throws caches=[xyzCache] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
at org.springframework.cache.interceptor.AbstractCacheResolver.resolveCaches(AbstractCacheR esolver.java:81)
at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:242)
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.<init>(CacheAspectSupport.java:675)
at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:255)
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContexts.<init>(CacheAspectSupport.java:581)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
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.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
Here is the java configuration that I am using to configure hazelcast.
HazelcastConfiguration.java
@EnableCaching
class HazelcastConfiguration {
@Bean
public Config getConfig() throws FileNotFoundException {
Config config;
if ((xmlConfigLocation == null) || (xmlConfigLocation.isEmpty())) {
// use default Hazelcast configuration
config = new Config();
} else {
// overlay custom xml config on default Hazelcast configuration.
config = new FileSystemXmlConfig(xmlConfigLocation);
}
//Trying to create cache config
MapConfig cache = new MapConfig();
cache.setName("xyzCache");
cache.getMaxSizeConfig().setSize(1);
cache.setMaxIdleSeconds(0);
cache.setTimeToLiveSeconds(86400);
cache.setEvictionPolicy(EvictionPolicy.LRU);
config.addMapConfig(cache);
}
}
Dependency used:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>3.6.8</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-cloud</artifactId>
<version>3.6.8</version>
</dependency>
Spring Boot Version: 1.4.6
Using these configuration, i am able to create and use hazelcast cache in application. After adding below dependency to provider jcache cache provider. Spring boot trying to use JCacheCacheConfiguration from its autoconfiguration and its cache manager.
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
Spring Boot starts the application without any exception or error. But as soon as i try to run first api call, it starts throwing me above exception. Any advice.?