When you use Ehcache, you find an obscure little problem.
The following code is in a model:
Public class Implements Serializable { privatestaticfinallong serialversionuid =- 990334519496260591L; Private Iuserservice US = ServiceManager.me.getUserService (); // Getter and Setter }
When you cache an instance of this model to Ehcache, you will be prompted with an error if Ehcache is configured to allow saving to disk:
ERROR diskstoragefactory Disk Write of xxxxxxx Failed:
java.io.notserializableexception:com.my.service.impl.userserviceimpl$ $EnhancerByGuice $$80ede2b6
Look at the error, it is clear that the Userserviceimpl object can not be serialized, it is ehcache the service logic also as the model of the normal properties
Under normal circumstances, the Userserviceimpl implementation of the Serializable interface can solve the problem
But in fact, this service is a stateless single-column pattern, it makes no sense to serialize it to disk, and it increases the IO overhead of the disk
How can you cache the model successfully and shaving the properties of these service logic?
At this time, an obscure keyword played a role:transient
Change the above code to the following, in fact, just add this keyword:
Public class Implements Serializable { privatestaticfinallong serialversionuid =- 990334519496260591L; Private iuserservice US = ServiceManager.me.getUserService (); // Getter and Setter }
When you cache again, the error will not be prompted.
Here is an article on the Transient keyword is elaborated in more detail: https://www.cnblogs.com/lanxuezaipiao/p/3369962.html
Resolving Ehcache serialization errors using the Transient keyword