Tag Archives: NoClassDefFoundError: Lorg/nustaq/serialization/FSTConfiguration

Spring boot project integration redisson throw exception NoClassDefFoundError: lorg / nustaq / serialization / fstconfiguration

When the spring boot project integrates redisson to do distributed locks, it throws an exception NoClassDefFoundError: lorg/nustaq/serialization/fstconfiguration. This paper summarizes the solution.

Problem background

When the spring boot project integrates redisson to configure distributed locks, the following exceptions are prompted:

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;

problem analysis

Due to the lack of FST dependency, add Maven dependency

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

Problem extension

What is FST?FST fast serialization is a re implemented development package for Java fast object serialization. Serialization is faster (2-10x), smaller, and compatible with JDK native serialization. JDK 1.7 support is required.

// ! 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();
}

References

https://www.oschina.net/p/FST