Where is the application context kept between user requests?


I am trying to understand what happens to the application context between two user requests? is it serialized somewhere? Is it kept in memory?


It is stored in the session (actually the ApplicationContext is the session). Normally Sessions are serialized by the container, but that is not a requirement.

Thanks for the answer. Please let me follow up with a more detailed question:

If the application context is stored in the session object, how do I program against the non-serializable/always-present part of my application? E.g., how do I use a database connection in my vaadin application? If I make the database connection a member of my application class, it will be stored in the session. That seems to be okay, until my application container starts serializing the session to store it persistently between requests. This behaviour can be found in Google App Engine for example, where the session is ALWAYS serialized, which implies my whole vaadin application has to be serializable. I undertand that storing the vaadin application context in the session makes sense, but that it is serialized does imply some major drawbacks which I am not able to resolve currently:

My application is built using Spring, including the IoC container of course. When a vaadin application is instantiated for a new user, I inject some database access object (query, save, update the database) into my newly created vaadin application class. This works fine until the GAE container wants to store the session and serializes it. Serialization of my vaadin application context causes the database access objects to be serialized also, which is not possible because hundreds of database access related classes would be serialized. Actually I would also consider this very bad design, because java web application stuff is mostly not programmed to be serialized and de-serialized all the time.

I could declare the database connection object transient, so it isn’t serialized, but than I would need to reinject it every time the vaadin application context is deserialized for a new request.

To summerize: Can someone point out how to handle/interface with parts of my web application that is not vaadin, such as database access, etc. … ?


In our project, we are using Spring & Annotation Driven Injection (e.g. @Configurable on the class and @Autowired annotations on dependencies).

By marking the variable definitions transient, when the objects are deserialized, they are automatically re-injected.



GAE for Java is not really designed for stateful applications, and does serialize and deserialize far too aggressively for such rather than trying to keep the sessions on the same node. We and others have tried to ask the GAE team to improve this, but I would not count on that happening. The performance (especially latencies) of GAE for applications with a large state is quite bad.

In other environments, serialization is primarily done for session persistence over server restarts, to manage a larger number of sessions than what fit in memory or for transferring sessions between nodes of a cluster (many clustering solutions try to optimize this).

Thanks for pointing this out. Maybe GAE is not the best choice for my application.

Charles, can you explain why declaring the injected variables transient makes them being reinjected?

Marking them as transient just means they are not written out when serialised.

If you are using weaving to inject the dependencies, then they are injected when the object is instantiated (there’s all sorts of below the covers stuff that happens - essentially AspectJ, which is used indirectly, modifies the constructor bytecode to inject the dependencies - and that is called, even when the object is created from de-serialization).

That’s my understanding, anyway.

Okay, now I got it. I have never been using weaving, why I was curious how your magic injection was performed.


You also can try my project
It enables auto-wiring after session deserialization without AOP/AspectJ byte code magic.

To my regret, for the present I haven’t time and enough English knowledge to finish this project and publish it as addon.

There are examples - how to create Spring application with Rhindoin.


  1. you should check does GAE support session passivation

  2. make mixed GAEApplicationServlet + SpringVaadinApplicationServlet = GAESpringVaadinApplicationServlet (Rhinodin is open for your contribution :wink:

  3. inherit your vaadin application from

    or better use RhinodinApplication “as is” (it is well suited for spring xml configuration) and put your code in Windows.

web.xml example: https://bitbucket.org/AndrewFink/rhinodin/src/tip/exampleSpringAndJs/web/WEB-INF/web.xml
spring xml examples


<bean id="vaadinApplicationTemplate" class="net.sf.apr.rhinodin.RhinodinApplication" scope="prototype" abstract="true" >
	<property name="authorizationRequired" value="SESSION_ATTR_ROLE" />
	<property name="loginUrl" value="$/auth"/><!-- I have plain old MVC stateless auth form - much lighter than vaadin -->
	<property name="loginUrlExplicit" value="$/auth?a=login"/>
	<property name="logoutURL" value="$/auth?a=off"/>
	<property name="theme" value="xt" />
	<!-- property name="userSessionAttribute" value="CLIENT_ID" / -->
	<property name="reqRoleName" value="admin" />
</bean><!-- vaadinApplicationTemplate -->