• storm java.io.NotSerializableException


    今天编写一个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

  • 相关阅读:
    vue嵌套路由
    不同的网络出现的报错
    yarn 创建react项目时出现错误
    vue-awsome-swiper竖向滚动出现空白
    SpringBoot路径映射
    ApplicationRunner接口
    CommandLineRunner接口
    springboot创建拦截器
    Cors跨域请求
    springboot自定义异常视图
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/9710801.html
Copyright © 2020-2023  润新知