public <T> void setCacheObject(final String key, final T value)
{
redisTemplate.opsForValue().set(key, value);
}
public <T> T getCacheObject(final String key)
{
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
}
这个逻辑在调用 getCacheObject 时 返回对象会随机变成 com.alibaba.fastjson.JSONObject 或者 com.alibaba.fastjson2.JSONObject 导致外部调用时报类型强制转换异常
就是 ruoyi 脚手架 里面的 RedisService TokenService 里面调用 getLoginUser 就会报 java.lang.ClassCastException: com.alibaba.fastjson2.JSONObject cannot be cast to com.ruoyi.system.api.model.LoginUser
而且之前都正常 一段时间没运行 再跑就出现这个问题 定义是在 RedisConfig
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
全部都是 object 获取到就变 JSONObject 了 实在是没搞懂哪里有问题