我想将对象保存到会话,并将这些会话保存到Redis。
Redis使用JdkSerializationRedisSerializer
作为默认序列化程序(在RedisOperationsSessionRepository
内部):
private RedisSerializer<Object> defaultSerializer = new JdkSerializationRedisSerializer();
为此,我要么
Serializable
保存或没有这个,我得到错误:SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type
如何覆盖redis序列化器?我找不到任何解决方案,并且以下解决方案似乎无法正常工作,因为我无法两次注入相同的bean,因此已经注入了它。 >
@Bean
public RedisOperationsSessionRepository sessionRepository(RedisTemplate<Object, Object> redisTemplate)
{
RedisOperationsSessionRepository sessionRepository = new RedisOperationsSessionRepository(redisTemplate);
sessionRepository.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
sessionRepository.setDefaultMaxInactiveInterval(300);
return sessionRepository;
}
我正在使用:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.1.3.RELEASE'
compile group: 'org.springframework.session', name: 'spring-session-data-redis', version: '2.1.4.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-redis', version: '2.1.5.RELEASE'
compile group: 'io.lettuce', name: 'lettuce-core', version: '5.1.4.RELEASE'