自定义统一RedisTemplate序列化机制

@Configuration
public class MyRedisConfig {
  /**
     * 自定义redis序列化
     * @param  * @param redisConnectionFactory 
     * @return org.springframework.data.redis.core.RedisTemplate<java.lang.Object,java.lang.Object>
     */
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
        RedisTemplate<Object, Object> template = new RedisTemplate();
        template.setConnectionFactory(redisConnectionFactory);
        GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer();
        template.setDefaultSerializer(serializer);
        return template;
    }
}

猜你喜欢

转载自blog.csdn.net/chengpeng1996/article/details/82969315