修改SpringBoot中RedisTemplate默认序列化为Json

该博客讲述了如何修改SpringBoot中RedisTemplate的默认序列化方式,从Java serialization更改为Json格式。作者通过查看源码发现SpringBoot使用StringRedisTemplate进行默认序列化,然后提供了一个使用@Configuration和@Bean注解的配置类示例,以实现Json格式保存对象到Redis中。
摘要由CSDN通过智能技术生成

背景

最近在使用redis保存对象时发现,对象是被序列化之后存入到redis中的,这样就不能直观的看到对象的属性信息,所以还是希望使用简单的json格式来保存对象到redis中。

那让我们来查看一下SpringBoot中默认的RedisTemplate的实现是什么

/**
 * Helper class that simplifies Redis data access code.
 * <p/>
 * Performs automatic serialization/deserialization between the given objects and the underlying binary data in the
 * Redis store. By default, it uses Java serialization for its objects (through {@link JdkSerializationRedisSerializer}
 * ). For String intensive operations consider the dedicated {@link StringRedisTemplate}.
 * <p/>
 * The central method is execute, supporting Redis access code implementing the {@link RedisCallback} interface. It
 * provides {@link RedisConnection} handling such that neither the {@link RedisCallback} implementation nor the calling
 * code needs to explicitly care about retrieving/closing Redis connections, or handling Connection lif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值