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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM