1. 程式人生 > >org.springframework.data.redis.serializer.SerializationException 解決方案

org.springframework.data.redis.serializer.SerializationException 解決方案

在使用Spring Data Redis的過程中,報瞭如下的異常

org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector

我的程式碼是把一個TreeSet集合存入了Redis中作為值.
TreeSet集合的構造方法中有一個比較器的內部類.
之後的解決方案是把TreeSet集合的值 ,放到List中,再存入Redis就不會報錯了.
呼叫list的addAll方法. 把TreeSet集合傳入進去即可
lists.addAll(treeset);