Class SpringVaadinServlet

  • All Implemented Interfaces:
    Constants, Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class SpringVaadinServlet
    extends VaadinServlet
    A VaadinServlet that associates and manages a Spring ConfigurableWebApplicationContext with each VaadinSession (aka, "Vaadin application" in the old terminology).

    The configLocation servlet parameter may be used to specify the Spring XML config file location(s). For example:

    
     <servlet>
         <servlet-name>My Vaadin App</servlet-name>
         <servlet-class>org.dellroad.stuff.vaadin7.SpringVaadinServlet</servlet-class>
         <init-param>
             <param-name>UI</param-name>
             <param-value>com.example.MyApplicationUI</param-value>
         </init-param>
         <init-param>
             <param-name>configLocation</param-name>
             <param-value>classpath:com/example/MyApplicationContext.xml</param-value>
         </init-param>
     </servlet>
     

    The main function of this servlet is to create and register a SpringVaadinSessionListener as a listener on the VaadinService associated with this servlet. The SpringVaadinSessionListener in turn detects the creation and destruction of Vaadin application instances (represented by VaadinSession instances) and does the work of managing the associated Spring application contexts.

    Use of this servlet in place of the standard Vaadin servlet is required for the @VaadinConfigurable annotation to work.

    Supported servlet parameters:

    Parameter Name Required? Description
    applicationName No Vaadin application name. Used for logging purposes and as the name of the XML application context file when configLocation is not specified. If this parameter is not specified, the name of the servlet is used.
    configLocation No Location of Spring application context XML file(s). Multiple locations are separated by whitespace. If omitted, /WEB-INF/ServletName.xml is used, where ServletName is the name of the Vaadin application (see applicationName).
    listenerClass No Specify the name of a custom class extending SpringVaadinSessionListener and having the same constructor arguments. If omitted, SpringVaadinSessionListener is used.
    sessionTracking No Boolean value that configures whether the SpringVaadinSessionListener should track Vaadin sessions; default false. If set to true, then getSessions() can be used to access all active sessions. Session tracking should not be used unless sessions are normally kept in memory; e.g., don't use session tracking when sessions are being serialized and persisted. See also VaadinSessionContainer.
    maxSessions No Configures a limit on the number of simultaneous Vaadin sessions that may exist at one time. Going over this limit will result in a ServiceException being thrown. A zero or negative number means there is no limit (this is the default). Ignored unless "sessionTracking" is set to true.

    Note: if any beans are declared scope="session" in your application context, you must register Spring's RequestContextListener as a listener in your web.xml (normally, Spring's DispatcherServlet would handle this task).

    See Also:
    SpringVaadinSessionListener, VaadinConfigurable, VaadinApplication, Serialized Form
    • Field Detail

      • CONFIG_LOCATION_PARAMETER

        public static final String CONFIG_LOCATION_PARAMETER
        Servlet initialization parameter ("configLocation") used to specify the location(s) of the Spring application context XML file(s). Multiple XML files may be separated by whitespace. This parameter is optional.
        See Also:
        Constant Field Values
      • APPLICATION_NAME_PARAMETER

        public static final String APPLICATION_NAME_PARAMETER
        Servlet initialization parameter ("applicationName") used to specify the name the application. This parameter is optional.
        See Also:
        Constant Field Values
      • SESSION_TRACKING_PARAMETER

        public static final String SESSION_TRACKING_PARAMETER
        Servlet initialization parameter ("sessionTracking") that enables tracking of all Vaadin session. This parameter is optional, and defaults to false.
        See Also:
        Constant Field Values
      • MAX_SESSIONS_PARAMETER

        public static final String MAX_SESSIONS_PARAMETER
        Servlet initialization parameter ("maxSessions") that configures the maximum number of simultaneous Vaadin sessions. Requires SESSION_TRACKING_PARAMETER to be set to true. This parameter is optional, and defaults to zero, which means no limit.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SpringVaadinServlet

        public SpringVaadinServlet()