springboot,redis 物件序列化配置
序列化配置
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
// 使用Jackson2JsonRedisSerialize序列化
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
// 物件序列化
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
// 設定key和value的序列化規則
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
相關文章
- springboot2.0 配置redis哨兵Spring BootRedis
- SpringBoot下用Kyro作為Redis序列化工具Spring BootRedis
- springboot自定義ObjectMapper序列化、配置序列化對LocalDateTime的支援Spring BootObjectAPPLDA
- SpringBoot+redis配置及測試Spring BootRedis
- springboot使用redis(從配置到實戰)Spring BootRedis
- 物件序列化(序列化)物件
- SpringBoot快取管理(三) 自定義Redis快取序列化機制Spring Boot快取Redis
- JavaScript 物件序列化JavaScript物件
- Python中物件序列化和反序列化Python物件
- redis的序列化(四)Redis
- SpringBoot2.0 redis生成組建和讀寫配置檔案Spring BootRedis
- .NET物件的XML序列化和反序列化物件XML
- SpringBoot使用RedisSpring BootRedis
- 【SpringBoot】整合RedisSpring BootRedis
- springboot整合redis?Spring BootRedis
- SpringBoot 整合 RedisSpring BootRedis
- SpringBoot整合RedisSpring BootRedis
- JavaScript物件序列化為JSONJavaScript物件JSON
- Java物件的序列化和反序列化實踐Java物件
- Java物件的序列化與反序列化-Json篇Java物件JSON
- Redis 反序列化異常Redis
- springboot 配置Spring Boot
- springboot配置Spring Boot
- SpringBoot物件複製Spring Boot物件
- Java基礎22--物件序列化和反序列化Java物件
- python json反序列化為物件PythonJSON物件
- 談談 JAVA 的物件序列化Java物件
- SpringBoot 使用 Redis GeoSpring BootRedis
- Redis在存取序列化和反序列化效能問題Redis
- jackson對Exception型別物件的序列化與反序列化Exception型別物件
- Redis物件系統Redis物件
- Redis - 物件結構Redis物件
- Redis有序集合物件Redis物件
- Redis 物件系統Redis物件
- 配置RedisRedis
- springboot 配置 httpsSpring BootHTTP
- springboot常用配置Spring Boot
- SpringBoot配置WebSocketSpring BootWeb