Spring Boot 1.X RedisCacheManager 配置方式

@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
RedisCacheManager cacheManager= new RedisCacheManager(redisTemplate);
cacheManager.setDefaultExpiration(60);
Map<String,Long> expiresMap=new HashMap<>();
expiresMap.put("Product",5L);
cacheManager.setExpires(expiresMap);
return cacheManager;
}

Spring Boot 2.X RedisCacheManager 配置方式

  /**
* SpringBoot 2.X 版本配置方式
*
* @param redisConnectionFactory
* @return
*/
@Bean
public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
// 解决查询缓存转换异常的问题
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
CacheKeyPrefix keyPrefix = new CacheKeyPrefix() {
@Override
public String compute(String cacheName) {
return cacheName + "::";
}
};
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
          //失效时间
.entryTtl(Duration.ofMinutes(3))
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
.disableCachingNullValues(); return RedisCacheManager.builder(redisConnectionFactory)
.cacheDefaults(config)
.build(); }

【Spring Boot】 Spring Boot 2.x 版本 CacheManager 配置方式的更多相关文章

  1. 5.2 spring5源码--spring AOP源码分析二--切面的配置方式

    目标: 1. 什么是AOP, 什么是AspectJ 2. 什么是Spring AOP 3. Spring AOP注解版实现原理 4. Spring AOP切面原理解析 一. 认识AOP及其使用 详见博 ...

  2. spring 整合 mybatis 中数据源的几种配置方式

    因为spring 整合mybatis的过程中, 有好几种整合方式,尤其是数据源那块,经常看到不一样的配置方式,总感觉有点乱,所以今天有空总结下. 一.采用org.mybatis.spring.mapp ...

  3. 【学习】Spring 的 AOP :基于Annotation 的“零配置”方式

    转自:http://www.cnblogs.com/jbelial/archive/2012/07/20/2539123.html AOP(Aspect Orient Programming ) , ...

  4. Spring Boot的配置文件-yml文件的集合配置方式

    yml集合数据的表示方式: 这种方式是配置普通的字符串—— 如果集合中装的是对象,就这么配置—— 行内配置方式—— map的配置方式——

  5. Spring IoC 依赖注入的方法大全 XML配置方式

    Spring 依赖注入 构造方法注入 ①   根据索引注入 <bean name="student" class="cn.bdqn.SpringDI.Student ...

  6. 【Spring Boot&&Spring Cloud系列】Spring Boot初识

    项目代码地址:https://github.com/AndyFlower/Spring-Boot-Learn/tree/master/Spring-boot-helloworld 一.Spring B ...

  7. spring boot 2.0.0由于版本不匹配导致的NoSuchMethodError问题解析

    spring boot升级到2.0.0以后,项目突然报出 NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBu ...

  8. Spring Cloud Alibaba与Spring Boot、Spring Cloud之间不得不说的版本关系

    这篇博文是临时增加出来的内容,主要是由于最近连载<Spring Cloud Alibaba基础教程>系列的时候,碰到读者咨询的大量问题中存在一个比较普遍的问题:版本的选择.其实这类问题,在 ...

  9. Spring Boot + Spring Cloud 实现权限管理系统 (Spring Security 版本 )

    技术背景 到目前为止,我们使用的权限认证框架是 Shiro,虽然 Shiro 也足够好用并且简单,但对于 Spring 官方主推的安全框架 Spring Security,用户群也是甚大的,所以我们这 ...

随机推荐

  1. SpringBoot 异步调用方法并接收返回值

    项目中肯定会遇到异步调用其他方法的场景,比如有个计算过程,需要计算很多个指标的值,但是每个指标计算的效率快慢不同,如果采用同步执行的方式,运行这一个过程的时间是计算所有指标的时间之和.比如: 方法A: ...

  2. Unable to bind to http://localhost:8080 on the IPv6 loopback interface: 'Cannot assign requested address'.

    .net core+nginx警告: warn: Microsoft.AspNetCore.Server.Kestrel[0] Unable to bind to http://localhost:5 ...

  3. CodeFirst与EntityFramework【续】

    3.    实现一对一的关系.在介绍一对多关系和多对多关系时,大家应该已经注意到了只要存在依赖关系的两个类的定义中包含对方的实例或实例的集合,Entity Framework Code First会自 ...

  4. Django rest-framework框架-CSRF验证

    settings.py里面有一个中间件 django.middleware.csrf.CsrfViewmiddleware  #如果注释掉全站不需要csrf验证  如果打开全站都要csrf验证 全局使 ...

  5. python之字符串类型的格式化

    python之字符串类型的格式化 要点:python字符串通过format()方法进行格式化处理.(Python语言同时支持两种字符串格式化方法,一种类似C语言中printf()函数的格式化方法,支持 ...

  6. Python与C/C++相互调用(转)

    原文链接 作者 一.问题 Python模块和C/C++的动态库间相互调用在实际的应用中会有所涉及,在此作一总结. 二.Python调用C/C++ 1.Python调用C动态链接库 Python调用C库 ...

  7. 8.SpringMVC注解式开发-HelloWorld

    第一个注解式开发程序 SpringMVC 是 Spring 框架的一部分,所以它和Spring结合的是非常紧密的 使用 @Controller 注解,既可以将处理器交给Spring容器去管理,又可以说 ...

  8. pycharm中代码窗口如何分成左右或者上下双栏

    操作步骤如下: 其中window->edit_tabs->Split Vertically 是分成左右双栏:选择Split Horizontally 是分成上下双栏

  9. Django drf:cbv源码、resful规范及接口、drf使用、response源码、序列化

    一.cbv源码分析 二.resful规范 三.django中写resful的借口 四.drf写resful的借口 五.APIVIew源码分析 六.drf之序列化 一.cbv源码分析 -CBV和FBV ...

  10. python 之math模块

    一.math 简介 import math # 导入模块 ret = dir(math) # 查看所有函数名列表 print(ret) # ['__doc__', '__loader__', '__n ...