先说明不是java代码的的问题,是redis缓存的问题
redis 在做缓存的时候序列化失败造成的,造成序列化失败。
解决策略:
一:
情况缓存数据库里面的缓存。刷新接口就好了
连接redis 选择库, flushdb
二:
在java bean 中 只能序列化id
总结:
两个方法都可以解决问题,但是各个方法各有优劣
方法一: 解决起来,快速,方便,但是如果缓存中数据比较多,会造成缓存雪崩,数据库的压力突然真加。同时下次新加字段,还是会出现这个问题,治标不治本。 所有不太推荐使用这个方法
方法二: 相比较方法一,需要修改代码,并重新编译,打包,并重启服务,繁琐点,但是这次解决后,以后不会在出现这个问题。一劳永逸。所有比较推荐用这个方法
示例代码
package com.example.demo03;
import com.example.demo03.bean.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework