报错:
DefaultSerializer requires a Serializable payload but received an object of type [com.pojo.User]
解决:
Java 对象必须实现 Serializable 接口
因为 Spring boot会将对象先序列化再存入 Redis
package redis.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
private String name;
private Integer age;
}
参考博客:
DefaultSerializer requires a Serializable payload but received an object of type [com.pojo.User]
- RedisSerializer RedisTemplate SpringBootredisserializer redistemplate springboot redisserializer redistemplate redis redistemplate springboot springboot实用技巧redistemplate多个 redistemplate序列springboot springboot redistemplate实例 多个 实战redistemplate springboot专题 redistemplate springboot解决方案 原因 redisserializer redistemplate