Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring session-scoped beans (controllers) and references to services, in terms of serialization
    text
    copied!<ul> <li>a standard case - you have a controller (<code>@Controller</code>) with <code>@Scope("session")</code>.</li> <li>classes put in the session usually are expected to implement <code>Serializable</code> so that they can be stored physically in case the server is restarted, for example</li> <li>If the controller implements <code>Serializable</code>, 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.</li> <li>It is not unlikely that some service, or even controller, hold a reference to the <code>ApplicationContext</code>, by implementing <code>ApplicationContextAware</code>, 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.</li> </ul> <p>So far I've mostly ignored these issues. Recently I thought of declaring all my spring dependencies <code>transient</code> and getting them back in <code>readResolve()</code> by the static utility classes <code>WebApplicationContextUtils</code> and such that hold the request/ServletContext in a <code>ThreadLocal</code>. This is tedious, but it guarantees that, when the object is deserialized, its dependencies will be "up to date" with the <em>current</em> application context.</p> <p>Is there any accepted practice for this, or any guidelines for serializing parts of the spring context.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload