Class ServletListenerRegistrationBean<T extends EventListener>
- java.lang.Object
- org.springframework.boot.web.servlet.RegistrationBean
- org.springframework.boot.web.servlet.ServletListenerRegistrationBean<T>
- Type Parameters:
T
- the type of listener
- All Implemented Interfaces:
ServletContextInitializer
,org.springframework.core.Ordered
public class ServletListenerRegistrationBean<T extends EventListener> extends RegistrationBean
AServletContextInitializer
to registerEventListener
s in a Servlet 3.0+ container. Similar to theregistration
features provided byServletContext
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
Constructor Summary
Constructors Constructor Description ServletListenerRegistrationBean()
Create a newServletListenerRegistrationBean
instance.ServletListenerRegistrationBean(T listener)
Create a newServletListenerRegistrationBean
instance.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
getDescription()
Return a description of the registration.T
getListener()
Return the listener to be registered.static Set<Class<?>>
getSupportedTypes()
Return the supported types for this registration.static boolean
isSupportedType(EventListener listener)
Returnstrue
if the specified listener is one of the supported types.protected void
register(String description, javax.servlet.ServletContext servletContext)
Register this bean with the servlet context.void
setListener(T listener)
Set the listener that will be registered.Methods inherited from class org.springframework.boot.web.servlet.RegistrationBean
getOrder, isEnabled, onStartup, setEnabled, setOrder
Constructor Detail
ServletListenerRegistrationBean
public ServletListenerRegistrationBean()
Create a newServletListenerRegistrationBean
instance.
ServletListenerRegistrationBean
public ServletListenerRegistrationBean(T listener)
Create a newServletListenerRegistrationBean
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 classRegistrationBean
- 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 classRegistrationBean
- Parameters:
description
- a description of the item being registeredservletContext
- the servlet context
isSupportedType
public static boolean isSupportedType(EventListener listener)
Returnstrue
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