jetcache
jetcache copied to clipboard
使用kryo序列化时候报错:Kryo Encode error. msg=Class is not registered: com.alicp.jetcache.CacheValueHolder
使用kryo作为序列化反序列化工具时报:Class is not registered: 用大神遇到过吗?跪求解决方案! 报错信息:
[2021-04-29 21:21:12,451] ERROR [] c.a.j.AbstractCache[58] - jetcache(RedisCache) PUT error. key=[[1]] com.alicp.jetcache.support.CacheEncodeException: Kryo Encode error. msg=Class is not registered: com.alicp.jetcache.CacheValueHolder Note: To register this class use: kryo.register(com.alicp.jetcache.CacheValueHolder.class); at com.alicp.jetcache.support.KryoValueEncoder.apply(KryoValueEncoder.java:66) at com.alicp.jetcache.support.KryoValueEncoder.apply(KryoValueEncoder.java:14) at com.alicp.jetcache.redis.RedisCache.do_PUT(RedisCache.java:163)
maven依赖:
代码:
@Cached(name="warehouse:code:", cacheType= CacheType.BOTH, expire = 3600, localExpire = 600, localLimit = 1000)
@Override
public WarehouseQO getWarehouseByCode(Long code) {
return warehouseMapper.selectByCode(code);
}
配置信:
jetcache: statIntervalMinutes: 15 areaInCacheName: false local: default: type: linkedhashmap keyConvertor: fastjson remote: default: type: redis keyConvertor: fastjson valueEncoder: kryo valueDecoder: kryo poolConfig: minIdle: 5 maxIdle: 20 maxTotal: 50 host: 192.168.111.109 port: 6379
断点调试一下吧,关键的类KryoValueDecoder,Kryo
解码出错但是没有错误堆栈导致缓存无法命中,经代码追踪发现实现了序列化的实体还必须有无参的构造函数
因为kryo5默认开启的类注册,具体如何关闭我没有去尝试也没有测试,我直接用的kryo4.0.2即可。
建议修改一下此类中 com.alicp.jetcache.support. KryoValueEncoder 23行: kryo.setDefaultSerializer(CompatibleFieldSerializer.class); 后面增加一行代码,关闭类注册 kryo.setRegistrationRequired(false);