Class VaadinApplication

  • All Implemented Interfaces:
    Serializable

    public class VaadinApplication
    extends Object
    implements Serializable
    A globally accessible "Vaadin application" singleton.

    At most one instance is associated with each VaadinSession (attempting to create more than one will result in an exception). This singleton instance is then always accessible from any Vaadin thread via get().

    Although this class does not require Spring, the singleton instance can be declared as a bean in the Spring XML application context created by a SpringVaadinSessionListener, which allows other beans and widgets in the Vaadin application context to autowire it and have access to the methods provided here:

    
      <bean class="org.dellroad.stuff.vaadin7.VaadinApplication"/>
     
    If your VaadinApplication instance allocates any resources on startup, be sure to configure it so that it cleans them up on application context shutdown, for example, by specifying destroy-method="...".

    If you are in a clustered environment and are subclassing this class, scope="session" is recommended; without it, there will be one instance per server+session rather than one unique instance per session. Of course, whether that matters depends on the semantics of the subclass fields. In any case, be aware that no instance will exist in session until the application context is refreshed.

    Note: using scope="session" requires adding a <listener> clause registering Spring's RequestContextListener in your web.xml.

    If this class is subclassed, additional application-specific fields and methods can be supplied to the entire application via the same mechanism. Subclasses can override init() for any application-specific initialization.

    Note: the singleton instance of this class is stored in the Vaadin session and is Serializable. Therefore, in a clustered environment, subclasses must be prepared to handle (de)serialization. Also, avoid declaring fields that reference this class in non-session-scope beans; instead, use VaadinApplication.get().

    See Also:
    SpringVaadinServlet, SpringVaadinSessionListener, VaadinService, Serialized Form