開發項目中用到reids,每次啓動都會有這種warning,雖然不影響程序繼續執行,但是看上去很煩人,
而且運維還以爲是程序有毛病
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.nustaq.serialization.FSTClazzInfo (file:/gradle_user_home/caches/modules-2/files-2.1/de.ruedigermoeller/fst/2.57/70583ffcab07a0c756428811dd108a342b575d2e/fst-2.57.jar) to field java.lang.String.value
WARNING: Please consider reporting this to the maintainers of org.nustaq.serialization.FSTClazzInfo
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
網上搜索很久,基本沒有好的方法,大多讓加參數忽略warning警告,這個其實很不安全,或許會錯過重要的warning
有人讓選不同fst版本測試看看,這樣不斷破壞了原本redission的依賴,好像也沒什麼效果
最後自食其力,自行解決啦
講重點
之所以有開頭的warning,是因爲redission默認code用的是jackson依賴fst
fst有問題,咱們不用他就行啦
序列化的選擇有很多,選擇避開fst:
編碼類名稱 說明
org.redisson.codec.JsonJacksonCodec Jackson JSON 編碼 默認編碼
org.redisson.codec.AvroJacksonCodec Avro 一個二進制的JSON編碼
org.redisson.codec.SmileJacksonCodec Smile 另一個二進制的JSON編碼
org.redisson.codec.CborJacksonCodec CBOR 又一個二進制的JSON編碼
org.redisson.codec.MsgPackJacksonCodec MsgPack 再來一個二進制的JSON編碼
org.redisson.codec.IonJacksonCodec Amazon Ion 亞馬遜的Ion編碼,格式與JSON類似
org.redisson.codec.KryoCodec Kryo 二進制對象序列化編碼
org.redisson.codec.SerializationCodec JDK序列化編碼
org.redisson.codec.FstCodec FST 10倍於JDK序列化性能而且100%兼容的編碼
org.redisson.codec.LZ4Codec LZ4 壓縮型序列化對象編碼
org.redisson.codec.SnappyCodec Snappy 另一個壓縮型序列化對象編碼
org.redisson.client.codec.JsonJacksonMapCodec 基於Jackson的映射類使用的編碼。可用於避免序列化類的信息,以及用於解決使用byte[]遇到的問題。
org.redisson.client.codec.StringCodec 純字符串編碼(無轉換)
org.redisson.client.codec.LongCodec 純整長型數字編碼(無轉換)
org.redisson.client.codec.ByteArrayCodec 字節數組編碼
org.redisson.codec.CompositeCodec 用來組合多種不同編碼在一起
甚至還可以自己fastjson來實現:
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import java.io.IOException;
public class FastjsonCodec extends BaseCodec {
private final Encoder encoder = in -> {
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream os = new ByteBufOutputStream(out);
JSON.writeJSONString(os, in,SerializerFeature.WriteClassName);
return os.buffer();
} catch (IOException e) {
out.release();
throw e;
} catch (Exception e) {
out.release();
throw new IOException(e);
}
};
private final Decoder<Object> decoder = (buf, state) ->
JSON.parseObject(new ByteBufInputStream(buf), Object.class);
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
}
@Override
public Encoder getValueEncoder() {
return encoder;
}
}
上面fastjson版本來自網絡,我沒有測試,如果您需要請自行驗證
我大多數用字符串,所以我選擇用
org.redisson.client.codec.StringCodec |
最後說下具體怎麼操作:
1,排除redission中的fst包
exclude group: 'de.ruedigermoeller', module: 'fst'
2,修改redission的配置文件,加入:
config.setCodec(new org.redisson.client.codec.StringCodec());
3,刷新gradle或者maven,重新構建項目
再次運行項目,就沒有煩人的warning啦