public class ServletRegistrationBean extends RegistrationBean
ServletContextInitializer
to register Servlet
s 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(ServletContext)
. URL mapping can be configured used setUrlMappings(java.util.Collection<java.lang.String>)
or
omitted when mapping to '/*'. The servlet name will be deduced if not specified.
ServletContextInitializer
,
ServletContext#addServlet(String, Servlet)
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ServletRegistrationBean()
Create a new
ServletRegistrationBean instance. |
ServletRegistrationBean(Servlet servlet,
String... urlMappings)
Create a new
ServletRegistrationBean instance with the specified
Servlet and URL mappings. |
Modifier and Type | Method and Description |
---|---|
void |
addUrlMappings(String... urlMappings)
Add URL mappings for the servlet.
|
protected void |
configure(ServletRegistration.Dynamic registration)
Configure registration settings.
|
MultipartConfigElement |
getMultipartConfig()
Returns the
multi-part configuration to be applied
or null . |
protected 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(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(MultipartConfigElement multipartConfig)
Set the the
multi-part configuration . |
void |
setServlet(Servlet servlet)
Sets the servlet to be registered.
|
void |
setUrlMappings(Collection<String> urlMappings)
Set the URL mappings for the servlet.
|
addInitParameter, getInitParameters, getOrDeduceName, getOrder, isAsyncSupported, isEnabled, setAsyncSupported, setEnabled, setInitParameters, setName, setOrder
public ServletRegistrationBean()
ServletRegistrationBean
instance.public ServletRegistrationBean(Servlet servlet, String... urlMappings)
ServletRegistrationBean
instance with the specified
Servlet
and URL mappings.servlet
- the servlet being mappedurlMappings
- the URLs being mappedprotected Servlet getServlet()
public void setServlet(Servlet servlet)
public void setUrlMappings(Collection<String> urlMappings)
urlMappings
- the mappings to setaddUrlMappings(String...)
public Collection<String> getUrlMappings()
public void addUrlMappings(String... urlMappings)
urlMappings
- the mappings to addsetUrlMappings(Collection)
public void setLoadOnStartup(int loadOnStartup)
loadOnStartup
priority. See
ServletRegistration.Dynamic#setLoadOnStartup
for details.public void setMultipartConfig(MultipartConfigElement multipartConfig)
multi-part configuration
.multipartConfig
- the muti-part configuration to set or null
public MultipartConfigElement getMultipartConfig()
multi-part configuration
to be applied
or null
.public String getServletName()
public void onStartup(ServletContext servletContext) throws ServletException
ServletContextInitializer
ServletContext
with any servlets, filters, listeners
context-params and attributes necessary for initialization.servletContext
- the ServletContext
to initializeServletException
- if any call against the given ServletContext
throws a ServletException
protected void configure(ServletRegistration.Dynamic registration)
configure
in class RegistrationBean
Copyright © 2015 Pivotal Software, Inc.. All rights reserved.