@Controller
) with @Scope("session")
.Serializable
so that they can be stored physically in case the server is restarted, for exampleSerializable
, this means all services (other spring beans) it is referring will also be serialized. They are often proxies, with references to transaction mangers, entity manager factories, etc.ApplicationContext
, by implementing ApplicationContextAware
, so this can effectively mean that the whole context is serialized. And given that it holds many connections - i.e. things that are not serializable by idea, it will be restored in corrupt state.So far I've mostly ignored these issues. Recently I thought of declaring all my spring dependencies transient
and getting them back in readResolve()
by the static utility classes WebApplicationContextUtils
and such that hold the request/ServletContext in a ThreadLocal
. This is tedious, but it guarantees that, when the object is deserialized, its dependencies will be "up to date" with the current application context.
Is there any accepted practice for this, or any guidelines for serializing parts of the spring context.
Note that in JSF, managed beans (~controllers) are stateful (unlike action-based web frameworks). So perhaps my question stands more for JSF, than for spring-mvc.
In this presentation (around 1:14) the speaker says that this issue is resolved in spring 3.0 by providing a proxy of non-serializable beans, which obtains an instance from the current application context (on deserialization)
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