Redis获取缓存异常:redis java.util.ArrayList cannot be cast to java.lang.String
在使用redis缓存数据时,增加一个配置类,修改key序列化器为string
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate();
//修改key的序列化器
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
若此时序列化redis中的value序列化为string,但是存储的数据类型为ArrayLsit等一系列对象时,运行时控制台就会报错 java.lang.ClassCastException
标签:lang,java,String,Redis,redis,template,序列化 From: https://www.cnblogs.com/dhhwl/p/16627201.html