不管eclipse仍是idea(默認關閉序列化提示,需手動打開),均可以自動生成相應的序列號,分爲兩類1L,XXXL。java
固然若是不指定,系統也會自動生成,可是存在隱性風險 ,不一樣的編譯器對同一個對象可能生成相同的序列號,也可能生成不一樣的序列號redis
java serialVersionUID在運行時基於該類的各個方面計算該類的默認 serialVersionUID 值,記住是運行時,因此哪怕是引用相同的jar包,最後的序列號也可能相同可能不一樣。spring
對象的序列化與反序列化最好顯示指定。api
在指定序列化值後,即便在後來的對象中添加了字段(沒有刪除與修改),序列化值是此前的,只要保證反序列化對象和最新的保持一致均能正常反序列化。eclipse
緣由:ide
沒有默認serialVersionUID ,在生成環境反序列化失敗,可是測試環境不管怎樣都不會有問題,引用了 相同的jar包,可是serialVersionUID 不是在編譯時指定,而是在運行時根據該類生成,因此即便引用相同的 jar包最後的 序列號也可能不同測試
在生成環境碰見如下錯誤idea
java.lang.IllegalArgumentException: Failed to deserialize object at org.springframework.util.SerializationUtils.deserialize(SerializationUtils.java:68) at com.sf.ccsp.inter.redis.RedisTemplate.getSerialization(RedisTemplate.java:2538) at com.sf.ccsp.inter.service.PLDKafkaMessageService.getCityName(PLDKafkaMessageService.java:368) at com.sf.ccsp.inter.service.PLDKafkaMessageService.coverToWaybillTO(PLDKafkaMessageService.java:105) at com.sf.ccsp.inter.service.PLDKafkaMessageService.handle(PLDKafkaMessageService.java:77) at com.sf.ccsp.inter.listener.FvpPldListener.onMessage(FvpPldListener.java:58) at com.sf.kafka.api.consume.KafkaConsumer$ConsumeTask.run(KafkaConsumer.java:230) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.InvalidClassException: com.sf.ccsp.basic.client.response.AddressResp; local class incompatible: stream c lassdesc serialVersionUID = 8651924817573918117, local class serialVersionUID = -7189267544850088870 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370) at org.springframework.util.SerializationUtils.deserialize(SerializationUtils.java:65) ... 11 more