zoukankan      html  css  js  c++  java
  • Spring boot 项目集成Redisson抛异常 NoClassDefFoundError: Lorg/nustaq/serialization/FSTConfiguration

    Spring boot 项目集成Redisson做分布式锁的时候,抛异常 NoClassDefFoundError: Lorg/nustaq/serialization/FSTConfiguration,本文总结一下解决方案。

    问题背景

    Spring boot 项目集成Redisson配置分布式锁的时候,提示如下异常:

    Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redisson' threw exception; nested exception is java.lang.NoClassDefFoundError: Lorg/nustaq/serialization/FSTConfiguration;
    

    问题分析

    缺少fst依赖导致的,添加maven依赖

    <dependency>
      <groupId>de.ruedigermoeller</groupId>
      <artifactId>fst</artifactId>
      <version>2.57</version>
    </dependency>
    

    问题延伸

    fst是什么?FST fast-serialization 是重新实现的 Java 快速对象序列化的开发包。序列化速度更快(2-10倍)、体积更小,而且兼容 JDK 原生的序列化。要求 JDK 1.7 支持。

    // ! reuse this Object, it caches metadata. Performance degrades massively
    // if you create a new Configuration Object with each serialization !
    static FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
    ...
    public MyClass myreadMethod(InputStream stream) throws IOException, ClassNotFoundException
    {
        FSTObjectInput in = conf.getObjectInput(stream);
        MyClass result = in.readObject(MyClass.class);
        // DON'T: in.close(); here prevents reuse and will result in an exception      
        stream.close();
        return result;
    }
    
    public void mywriteMethod( OutputStream stream, MyClass toWrite ) throws IOException 
    {
        FSTObjectOutput out = conf.getObjectOutput(stream);
        out.writeObject( toWrite, MyClass.class );
        // DON'T out.close() when using factory method;
        out.flush();
        stream.close();
    }
    

    Reference


      读后有收获,小礼物走一走,请作者喝咖啡。

    赞赏支持

  • 相关阅读:
    微信第三方平台处理授权公众号的网页授权接口
    CentOS7配置图形界面及设置vnc远程连接、windows远程桌面连接
    CentOS7安装及配置vsftpd (FTP服务器)
    Asp.net Core发布到CentOS7
    MySQL常用命令整理
    CentOS7.0安装Nginx
    Android常用错误解决汇总
    C#调用百度云存储接口上传文件
    面试:实现二叉搜索树的查找、插入和删除操作
    面试:C++输入数据
  • 原文地址:https://www.cnblogs.com/east7/p/15376681.html
Copyright © 2011-2022 走看看