org.springframework.boot.context.embedded
Class ServletRegistrationBean

java.lang.Object
  extended by org.springframework.boot.context.embedded.RegistrationBean
      extended by org.springframework.boot.context.embedded.ServletRegistrationBean
All Implemented Interfaces:
ServletContextInitializer

public class ServletRegistrationBean
extends RegistrationBean

A ServletContextInitializer to register Servlets in a Servlet 3.0+ container. Similar to the registration features provided by ServletContext but with a Spring Bean friendly design.

The servlet must be specified before calling onStartup(javax.servlet.ServletContext). URL mapping can be configured used setUrlMappings(java.util.Collection) or omitted when mapping to '/*'. The servlet name will be deduced if not specified.

Author:
Phillip Webb
See Also:
ServletContextInitializer, ServletContext.addServlet(String, Servlet)

Constructor Summary
ServletRegistrationBean()
          Create a new ServletRegistrationBean instance.
ServletRegistrationBean(javax.servlet.Servlet servlet, String... urlMappings)
          Create a new ServletRegistrationBean instance with the specified Servlet and URL mappings.
 
Method Summary
 void addUrlMappings(String... urlMappings)
          Add URL mappings for the servlet.
protected  void configure(javax.servlet.ServletRegistration.Dynamic registration)
          Configure registration settings.
 javax.servlet.MultipartConfigElement getMultipartConfig()
          Returns the multi-part configuration to be applied or null.
protected  javax.servlet.Servlet getServlet()
          Returns the servlet being registered.
 String getServletName()
          Returns the servlet name that will be registered.
 Collection<String> getUrlMappings()
          Return a mutable collection of the URL mappings for the servlet.
 void onStartup(javax.servlet.ServletContext servletContext)
          Configure the given ServletContext with any servlets, filters, listeners context-params and attributes necessary for initialization.
 void setLoadOnStartup(int loadOnStartup)
          Sets the loadOnStartup priority.
 void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
          Set the the multi-part configuration.
 void setServlet(javax.servlet.Servlet servlet)
          Sets the servlet to be registered.
 void setUrlMappings(Collection<String> urlMappings)
          Set the URL mappings for the servlet.
 
Methods inherited from class org.springframework.boot.context.embedded.RegistrationBean
addInitParameter, configure, getInitParameters, getOrDeduceName, isAsyncSupported, setAsyncSupported, setInitParameters, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletRegistrationBean

public ServletRegistrationBean()
Create a new ServletRegistrationBean instance.


ServletRegistrationBean

public ServletRegistrationBean(javax.servlet.Servlet servlet,
                               String... urlMappings)
Create a new ServletRegistrationBean instance with the specified Servlet and URL mappings.

Parameters:
servlet - the servlet being mapped
urlMappings - the URLs being mapped
Method Detail

getServlet

protected javax.servlet.Servlet getServlet()
Returns the servlet being registered.


setServlet

public void setServlet(javax.servlet.Servlet servlet)
Sets the servlet to be registered.


setUrlMappings

public void setUrlMappings(Collection<String> urlMappings)
Set the URL mappings for the servlet. If not specified the mapping will default to '/'. This will replace any previously specified mappings.

Parameters:
urlMappings - the mappings to set
See Also:
addUrlMappings(String...)

getUrlMappings

public Collection<String> getUrlMappings()
Return a mutable collection of the URL mappings for the servlet.

Returns:
the urlMappings

addUrlMappings

public void addUrlMappings(String... urlMappings)
Add URL mappings for the servlet.

Parameters:
urlMappings - the mappings to add
See Also:
setUrlMappings(Collection)

setLoadOnStartup

public void setLoadOnStartup(int loadOnStartup)
Sets the loadOnStartup priority. See ServletRegistration.Dynamic#setLoadOnStartup for details.


setMultipartConfig

public void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
Set the the multi-part configuration.

Parameters:
multipartConfig - the muti-part configuration to set or null

getMultipartConfig

public javax.servlet.MultipartConfigElement getMultipartConfig()
Returns the multi-part configuration to be applied or null.


getServletName

public String getServletName()
Returns the servlet name that will be registered.


onStartup

public void onStartup(javax.servlet.ServletContext servletContext)
               throws javax.servlet.ServletException
Description copied from interface: ServletContextInitializer
Configure the given ServletContext with any servlets, filters, listeners context-params and attributes necessary for initialization.

Parameters:
servletContext - the ServletContext to initialize
Throws:
javax.servlet.ServletException - if any call against the given ServletContext throws a ServletException

configure

protected void configure(javax.servlet.ServletRegistration.Dynamic registration)
Configure registration settings. Subclasses can override this method to perform additional configuration if required.



Copyright © 2013. All Rights Reserved.