1. 程式人生 > >storm java.io.NotSerializableException

storm java.io.NotSerializableException

div topo fail viso clas https proc this str

今天編寫一個storm的topology,bolt的邏輯跟之前的類似。

為了減少重復代碼,我建了個抽象基類,存放bolt的公共邏輯,設計了幾個abstract方法,不同的邏輯部分由子類實現。

基類日誌定義如下:

private static final Logger LOG = LoggerFactory.getLogger(AbstractXxxBolt.class);

Logger是項目封裝的,用於ELK的對象,考慮到子類可能用到,我把它的static去掉,AbstractXxxBolt.class改成了getClass();

本機啟動topology報錯:storm java.io.NotSerializableException

Logger;

改回static後,啟動正常;

子類中,有引用其它工程的dubbo服務接口,開始寫在構造函數中初始化的,

private XxxService xxxService;

SubClass() {
   super();
   xxxService = XxxUtil.getBean(XxxService.class);
}

本機啟動topology報錯:storm NotSerializableException com.alibaba.dubbo.common.bytecode.proxy0

解決方法:

將子類構造函數中的賦值去掉,抽象一個doPrepare()方法,在基類的prepare()方法中調用

子類實現doPrepare(),在其中xxxService = XxxUtil.getBean(XxxService.class);

-----------------------------------------------------------------------------------------------------------------------------

The supervisor instantiates the bolts, sends them to the workers, and then calls prepare() on all of them. Therefore, anything


that isn‘t serializable that is instantiated before prepare() causes this process to fail.

-----------------------------------------------------------------------------------------------------------------------------

參考:

https://blog.csdn.net/wanghai__/article/details/8997895

storm java.io.NotSerializableException