自定义统一RedisTemplate序列化机制

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

你可能感兴趣的:(redis)