Why should bean classes be serialized?
I have seen bean classes in posts about spring MVC and they are always declared serialized and have a private static final long serialVersionUID
. Why?
One good reason, with respect to servlets, is that if you put serializable beans into your web server session, your web server can serialize them to disk if it's shutting down, and then deserialize them back into memory when it starts up. In this way, users wouldn't lose their sessions / logins when the server comes back up.
If there are any non-serializable beans in session, tomcat will fail to serialize sessions to disk.
I believe it's also necessary if you want to sync sessions between multiple servers in a cluster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With