Package Com.zm.blog.config.redis;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;
Import Org.springframework.data.redis.connection.RedisConnectionFactory;
Import Org.springframework.data.redis.core.RedisTemplate;
Import Org.springframework.data.redis.core.StringRedisTemplate;
Import Org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
Import Com.fasterxml.jackson.annotation.JsonAutoDetect;
Import Com.fasterxml.jackson.annotation.PropertyAccessor;
Import Com.fasterxml.jackson.databind.ObjectMapper; @Configuration public class redisconfig{@SuppressWarnings ({"Rawtypes", "Unchecked"}) @Bean public Redistemplat E<string, string> redistemplate (Redisconnectionfactory Factory) {stringredistemplate template = new StringR
Edistemplate (Factory);
Jackson2jsonredisserializer Jackson2jsonredisserializer = new Jackson2jsonredisserializer (Object.class); Objectmapper om = new OBjectmapper ();
Om.setvisibility (Propertyaccessor.all, JsonAutoDetect.Visibility.ANY);
Om.enabledefaulttyping (ObjectMapper.DefaultTyping.NON_FINAL);
Jackson2jsonredisserializer.setobjectmapper (OM);
Template.setvalueserializer (Jackson2jsonredisserializer);
Template.afterpropertiesset ();
return template;
}
}