我有使用hazelcast集成的spring-boot应用程序。
现在我需要添加ehcache支持。 @EnableCaching
创建Hazelcast CacheManager。我的目标是使用@Cachable
和ehcache 3。
我试图手动定义Ehcache CacheManager
@Bean
public CacheManager ehcache() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
cacheManager.init();
return cacheManager;
}
但我得到了:
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'ehcache' is expected to be of type 'org.springframework.cache.CacheManager' but was actually of type 'org.ehcache.core.EhcacheManager'.
答案 0 :(得分:2)
对于Ehcache 3,您必须使用JCacheCacheManager
来包装Ehcache CacheManager
并将其转换为Spring CacheManager
。有一个例子here。
@Bean
public CacheManager cacheManager() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
JCacheCacheManager jCacheCacheManager = new JCacheCacheManager(cacheManager);
return jCacheCacheManager;
}