Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring services should be serializable

I am developing Spring-mvc application.

I am getting NotSerializableException.

The exception is coming on the restart of the server. I search for the solution and got to know that session scoped beans should be serialized.

My session scoped bean implements serializable, but it gives exception for injected beans and services.

It asks me to serialize all injected beans and services.

I have serialized my beans but is it required to serialize services also.

Is it accepted behavior to serialize services also? If yes then will I have to serialize all the services in my applications?

Thanks.

like image 847
Naman Gala Avatar asked Dec 29 '25 08:12

Naman Gala


1 Answers

Tomcat does serialize session scope bean whenever you restart or shutdown it and restore the session while starting. You can implement serializable for beans which you want to be restored. otherwise skip this error.

Edit: Making a class serializable means that class must not contain non-serializable references or those references must be declared transient.

While deserializing the object, transient fields will reset to default value, so you might need to reinitialize it using if( transientField == null) { .. }

like image 62
Mahendra Avatar answered Dec 31 '25 22:12

Mahendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!