org.springframework.boot.web.servlet

Class ServletListenerRegistrationBean<T extends EventListener>

  • Type Parameters:
    T - the type of listener
    All Implemented Interfaces:
    ServletContextInitializer, org.springframework.core.Ordered


    public class ServletListenerRegistrationBean<T extends EventListener>
    extends RegistrationBean
    A ServletContextInitializer to register EventListeners in a Servlet 3.0+ container. Similar to the registration features provided by ServletContext but with a Spring Bean friendly design. This bean can be used to register the following types of listener:
    • ServletContextAttributeListener
    • ServletRequestListener
    • ServletRequestAttributeListener
    • HttpSessionAttributeListener
    • HttpSessionListener
    • ServletContextListener
    Since:
    1.4.0
    Author:
    Dave Syer, Phillip Webb
    • Constructor Detail

      • ServletListenerRegistrationBean

        public ServletListenerRegistrationBean(T listener)
        Create a new ServletListenerRegistrationBean instance.
        Parameters:
        listener - the listener to register
    • Method Detail

      • setListener

        public void setListener(T listener)
        Set the listener that will be registered.
        Parameters:
        listener - the listener to register
      • getListener

        public T getListener()
        Return the listener to be registered.
        Returns:
        the listener to be registered
      • getDescription

        protected String getDescription()
        Description copied from class: RegistrationBean
        Return a description of the registration. For example "Servlet resourceServlet"
        Specified by:
        getDescription in class RegistrationBean
        Returns:
        a description of the registration
      • register

        protected void register(String description,
                                javax.servlet.ServletContext servletContext)
        Description copied from class: RegistrationBean
        Register this bean with the servlet context.
        Specified by:
        register in class RegistrationBean
        Parameters:
        description - a description of the item being registered
        servletContext - the servlet context
      • isSupportedType

        public static boolean isSupportedType(EventListener listener)
        Returns true if the specified listener is one of the supported types.
        Parameters:
        listener - the listener to test
        Returns:
        if the listener is of a supported type
      • getSupportedTypes

        public static Set<Class<?>> getSupportedTypes()
        Return the supported types for this registration.
        Returns:
        the supported types

Copyright © 2020 Pivotal Software, Inc.. All rights reserved.