首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何强制spring (boot)使用ehcahe 3

如何强制spring (boot)使用ehcahe 3
EN

Stack Overflow用户
提问于 2018-02-20 21:25:09
回答 1查看 1.2K关注 0票数 0

我有与hazelcast集成的spring-boot应用程序。现在我需要添加ehcache支持。@EnableCaching创建了Hazelcast CacheManager。我的目标是在ehcache3中使用@Cachable

我尝试手动定义Ehcache CacheManager

代码语言:javascript
复制
  @Bean
  public CacheManager ehcache() {
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
    cacheManager.init();
    return cacheManager;
  }

但我有:

代码语言:javascript
复制
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'.
EN

回答 1

Stack Overflow用户

发布于 2018-02-20 21:38:47

对于Ehcache3,您必须使用JCacheCacheManager来包装Ehcache CacheManager并将其转换为Spring CacheManager。available here就是一个例子。

代码语言:javascript
复制
@Bean
public CacheManager cacheManager() {
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
    JCacheCacheManager jCacheCacheManager = new JCacheCacheManager(cacheManager);
    return jCacheCacheManager;
 }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48886351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档