【发布时间】:2018-11-28 08:12:13
【问题描述】:
尝试使用带有 GenericJackson2JsonRedisSerializer 的 RedisTemplate bean,但在调试时我注意到 Spring Session 使用了不同的 RedisTemplate 实例。
@Configuration
@EnableRedisHttpSession
public class RedisHttpSessionConfig extends
AbstractHttpSessionApplicationInitializer {
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory();
}
@Bean
public RedisTemplate<Object, Object> redisTemplate() {
final RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
@Bean
public HttpSessionEventPublisher httpSessionEventPublisher() {
return new HttpSessionEventPublisher();
}
运行时,Spring Session 似乎对 hashValues 使用默认的 JdkSerializationRedisSerializer,而不是所需的 GenericJackson2JsonRedisSerializer。
删除 extends AbstractHttpSessionApplicationInitializer 似乎使 Spring 使用正确的 RedisTempplate bean,但 Spring Session 根本没有连接。
使用 Spring Session 1.3.3 和 spring-boot-starter-data -redis 1.5.13。
知道我错过了什么吗?
【问题讨论】:
标签: spring spring-boot spring-security redis spring-session