标签:anti div color 本机 static font alibaba ant iso
今天编写一个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
标签:anti div color 本机 static font alibaba ant iso
原文地址:https://www.cnblogs.com/cdfive2018/p/9710801.html