使用Redis在SpringBoot中将对象添加到HttpSession失败

时间:2016-04-09 20:31:20

标签: java redis spring-boot httpsession

当我尝试将对象添加到会话中时,如下所示:

HttpSession session = ....
MyObject object = ....
session.setAttribute("my_object", object);

然后我得到一个例外:

org.springframework.data.redis.serializer.SerializationException: 
Cannot serialize; nested exception is   
org.springframework.core.serializer.support.SerializationFailedException:
Failed to serialize object using DefaultSerializer; nested exception is 
java.lang.IllegalArgumentException: DefaultSerializer requires a  
Serializable payload but received an object of type [MyObject]

我应该怎么做才能指示REDIS序列化对象MyObject

1 个答案:

答案 0 :(得分:3)

我猜这个异常已经告诉你出了什么问题。 只需尝试MyObject实施Serializable

即可