我正在尝试将 jcache 与 hazelcast 服务器提供商一起使用。但得到这个例外。
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)
这是我用来配置 hazelcast 的 java 配置。
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>
<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 版本:1.4.6
使用这些配置,我可以在应用程序中创建和使用 hazelcast 缓存。将以下依赖项添加到提供程序 jcache 缓存提供程序后。Spring boot 尝试从其自动配置和缓存管理器中使用 JCacheCacheConfiguration。
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
Spring Boot 启动应用程序时没有任何异常或错误。但是,一旦我尝试运行第一个 api 调用,它就会开始将我抛到异常之上。有什么建议吗?