类 ServletRegistrationBean
- java.lang.Object
- org.springframework.boot.web.servlet.RegistrationBean
- org.springframework.boot.web.servlet.ServletRegistrationBean
- 所有已实现的接口:
ServletContextInitializer
,org.springframework.core.Ordered
public class ServletRegistrationBean extends RegistrationBean
AServletContextInitializer
to registerServlet
s in a Servlet 3.0+ container. Similar to theregistration
features provided byServletContext
but with a Spring Bean friendly design.The
servlet
must be specified before callingonStartup(javax.servlet.ServletContext)
. URL mapping can be configured usedsetUrlMappings(java.util.Collection<java.lang.String>)
or omitted when mapping to '/*' (unlessalwaysMapUrl
is set tofalse
). The servlet name will be deduced if not specified.- 从以下版本开始:
- 1.4.0
- 另请参阅:
ServletContextInitializer
,ServletContext.addServlet(String, Servlet)
构造器概要
构造器 构造器 说明 ServletRegistrationBean()
Create a newServletRegistrationBean
instance.ServletRegistrationBean(javax.servlet.Servlet servlet, boolean alwaysMapUrl, String... urlMappings)
Create a newServletRegistrationBean
instance with the specifiedServlet
and URL mappings.ServletRegistrationBean(javax.servlet.Servlet servlet, String... urlMappings)
Create a newServletRegistrationBean
instance with the specifiedServlet
and URL mappings.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 themulti-part configuration
to be applied ornull
.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 givenServletContext
with any servlets, filters, listeners context-params and attributes necessary for initialization.void
setLoadOnStartup(int loadOnStartup)
Sets theloadOnStartup
priority.void
setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
Set themulti-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.从类继承的方法 org.springframework.boot.web.servlet.RegistrationBean
addInitParameter, configure, getInitParameters, getOrDeduceName, getOrder, isAsyncSupported, isEnabled, setAsyncSupported, setEnabled, setInitParameters, setName, setOrder
构造器详细资料
ServletRegistrationBean
public ServletRegistrationBean()
Create a newServletRegistrationBean
instance.
ServletRegistrationBean
public ServletRegistrationBean(javax.servlet.Servlet servlet, String... urlMappings)
Create a newServletRegistrationBean
instance with the specifiedServlet
and URL mappings.- 参数:
servlet
- the servlet being mappedurlMappings
- the URLs being mapped
ServletRegistrationBean
public ServletRegistrationBean(javax.servlet.Servlet servlet, boolean alwaysMapUrl, String... urlMappings)
Create a newServletRegistrationBean
instance with the specifiedServlet
and URL mappings.- 参数:
servlet
- the servlet being mappedalwaysMapUrl
- if omitted URL mappings should be replaced with '/*'urlMappings
- the URLs being mapped
方法详细资料
getServlet
protected javax.servlet.Servlet getServlet()
Returns the servlet being registered.- 返回:
- the servlet
setServlet
public void setServlet(javax.servlet.Servlet servlet)
Sets the servlet to be registered.- 参数:
servlet
- the servlet
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.- 参数:
urlMappings
- the mappings to set- 另请参阅:
addUrlMappings(String...)
getUrlMappings
public Collection<String> getUrlMappings()
Return a mutable collection of the URL mappings for the servlet.- 返回:
- the urlMappings
addUrlMappings
public void addUrlMappings(String... urlMappings)
Add URL mappings for the servlet.- 参数:
urlMappings
- the mappings to add- 另请参阅:
setUrlMappings(Collection)
setLoadOnStartup
public void setLoadOnStartup(int loadOnStartup)
Sets theloadOnStartup
priority. SeeServletRegistration.Dynamic.setLoadOnStartup(int)
for details.- 参数:
loadOnStartup
- if load on startup is enabled
setMultipartConfig
public void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
Set themulti-part configuration
.- 参数:
multipartConfig
- the multi-part configuration to set ornull
getMultipartConfig
public javax.servlet.MultipartConfigElement getMultipartConfig()
Returns themulti-part configuration
to be applied ornull
.- 返回:
- the multipart config
getServletName
public String getServletName()
Returns the servlet name that will be registered.- 返回:
- the servlet name
onStartup
public void onStartup(javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException
从接口复制的说明:ServletContextInitializer
Configure the givenServletContext
with any servlets, filters, listeners context-params and attributes necessary for initialization.- 参数:
servletContext
- theServletContext
to initialize- 抛出:
javax.servlet.ServletException
- if any call against the givenServletContext
throws aServletException
configure
protected void configure(javax.servlet.ServletRegistration.Dynamic registration)
Configure registration settings. Subclasses can override this method to perform additional configuration if required.- 参数:
registration
- the registration