I have searched online for a few days, but only find that my object is not implementing serializable? Which object? DataKey or ResponseEntity? I can't reproduce this error in my local and I can only see this error in remote server log.
Updated: Since this issue is only happening when trying to refresh a cache object, first time load into cache does not have this issue, so I apply the fix by setting overflowToDisk="false" in ehcache.xml, and issue gone.
2020-03-30_12:15:30.941 [refdata.data] ERROR n.s.e.store.disk.DiskStorageFactory - Disk Write of DataKey [refDataType=Machine, subDataType=Laptop] failed:
java.io.NotSerializableException: org.springframework.http.ResponseEntity
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)2
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
at net.sf.ehcache.Element.writeObject(Element.java:875)
at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97)
at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:403)
at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:385)
at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:477)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1071)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1055)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run
java.io.NotSerializableException: org.springframework.http.ResponseEntityis perfectly clear. You shouldn't be trying to cache a response. - user207421ResponseEntityor you are referencing to one in one of your serializable objects. - Amir PashazadehSerializable(i.e. implement theSerializableinterface) if you want to cache it. If you look at ResponseEntity javadoc it clearly isn't serializable - which is why you got the error. Of course you could cache thebody()and that should work. - Mr R