springboot连接Redis报错Servlet.service() for servlet [dispatcherServlet] in context with path [] threw e

搞了一天,最后11点多解决了,记录一下。
就是在启动的时候报错,大概意思是说不能序列化(.SerializationException: Cannot serialize)
问题:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 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.io.NotSerializableException: com.wanghaixin.springboot.model.Student] with root cause

解决方法:
NotSerializable即为不可序列化的对象,对象Article不可序列化因此出现了此问题。

要缓存的JavaBean必须实现Serializable接口,因为Spring会将对象先序列化再存入 Redis

针对于此异常,修改对应的JavaBean对象即可,我的是student

public class Student implements Serializable 

你可能感兴趣的:(springboot,java,redis,spring,spring,boot)