My spring stores session into redis, but the key is like "\xac\xed\x00\x05t\x00(spring:session". Now I want to remove the weird prefix and I know the solution is using StringRedisSerializer in RedisTemplate, but my config code below does not work:
@EnableRedisHttpSession()
@Configuration
public class SpringSessionConfig {
@Autowired
JedisConnectionFactory jedisConnectionFactory;
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(StandardCharsets.UTF_8);
@Bean
public StringRedisTemplate redisTemplate() {
StringRedisTemplate redisTemplate = new StringRedisTemplate();
redisTemplate.setConnectionFactory(this.jedisConnectionFactory);
redisTemplate.setDefaultSerializer(this.stringRedisSerializer);
redisTemplate.setHashKeySerializer(this.stringRedisSerializer);
redisTemplate.setKeySerializer(this.stringRedisSerializer);
return redisTemplate;
}
}
There are answers that using xml config file to do the same thing, but I prefer using pure java code, anyone can help with the above code? Thx.