T
- the type of the Servlet
to registerpublic class ServletRegistrationBean<T extends javax.servlet.Servlet> extends DynamicRegistrationBean<javax.servlet.ServletRegistration.Dynamic>
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
RegistrationBean.onStartup(javax.servlet.ServletContext)
. URL mapping can be configured used setUrlMappings(java.util.Collection<java.lang.String>)
or
omitted when mapping to '/*' (unless
alwaysMapUrl
is set to
false
). The servlet name will be deduced if not specified.
ServletContextInitializer
,
ServletContext.addServlet(String, Servlet)
Constructor and Description |
---|
ServletRegistrationBean()
Create a new
ServletRegistrationBean instance. |
ServletRegistrationBean(T servlet,
boolean alwaysMapUrl,
String... urlMappings)
Create a new
ServletRegistrationBean instance with the specified
Servlet and URL mappings. |
ServletRegistrationBean(T servlet,
String... urlMappings)
Create a new
ServletRegistrationBean instance with the specified
Servlet and URL mappings. |
Modifier and Type | Method and Description |
---|---|
protected javax.servlet.ServletRegistration.Dynamic |
addRegistration(String description,
javax.servlet.ServletContext servletContext) |
void |
addUrlMappings(String... urlMappings)
Add URL mappings, as defined in the Servlet specification, for the servlet.
|
protected void |
configure(javax.servlet.ServletRegistration.Dynamic registration)
Configure registration settings.
|
protected String |
getDescription()
Return a description of the registration.
|
javax.servlet.MultipartConfigElement |
getMultipartConfig()
Returns the
multi-part configuration to be applied
or null . |
protected T |
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, as defined in the Servlet
specification, for the servlet.
|
void |
setLoadOnStartup(int loadOnStartup)
Sets the
loadOnStartup priority. |
void |
setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
Set the
multi-part configuration . |
void |
setServlet(T servlet)
Sets the servlet to be registered.
|
void |
setUrlMappings(Collection<String> urlMappings)
Set the URL mappings for the servlet.
|
addInitParameter, getInitParameters, getOrDeduceName, isAsyncSupported, register, setAsyncSupported, setInitParameters, setName
getOrder, isEnabled, onStartup, setEnabled, setOrder
public ServletRegistrationBean()
ServletRegistrationBean
instance.public ServletRegistrationBean(T servlet, String... urlMappings)
ServletRegistrationBean
instance with the specified
Servlet
and URL mappings.servlet
- the servlet being mappedurlMappings
- the URLs being mappedpublic ServletRegistrationBean(T servlet, boolean alwaysMapUrl, String... urlMappings)
ServletRegistrationBean
instance with the specified
Servlet
and URL mappings.servlet
- the servlet being mappedalwaysMapUrl
- if omitted URL mappings should be replaced with '/*'urlMappings
- the URLs being mappedprotected T getServlet()
public void setServlet(T servlet)
servlet
- the servletpublic 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.loadOnStartup
- if load on startup is enabledpublic void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
multi-part configuration
.multipartConfig
- the multi-part configuration to set or null
public javax.servlet.MultipartConfigElement getMultipartConfig()
multi-part configuration
to be applied
or null
.protected String getDescription()
RegistrationBean
getDescription
in class RegistrationBean
protected javax.servlet.ServletRegistration.Dynamic addRegistration(String description, javax.servlet.ServletContext servletContext)
addRegistration
in class DynamicRegistrationBean<javax.servlet.ServletRegistration.Dynamic>
protected void configure(javax.servlet.ServletRegistration.Dynamic registration)
configure
in class DynamicRegistrationBean<javax.servlet.ServletRegistration.Dynamic>
registration
- the registrationpublic String getServletName()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.