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
Similar Posts:
- [Solved] Springboot startup error: org.springframework.beans.factory.unsatisfieddependenceexception…
- Spring cloud consumer feign injection error [How to Solve]
- Property ‘dataSource’ threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
- mybatis: Property ‘configuration’ and ‘configLocation’ can not specified with together
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans’ defined in class path resource
- [Solved] Zookeeper reads data error: Exception in thread “main” org.I0Itec.zkclient.exception.ZkMarshallingError…
- Spring Error: Bean instantiation via factory method failed StackOverflowError
- Failed to deserialize — local class incompatible: stream classdesc serialVersionUID [Solved]
- Springcloud: gateway module startup error
- [Solved] Java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException