Class ServletRegistrationBean<T extends Servlet>
java.lang.Object
org.springframework.boot.web.servlet.RegistrationBean
org.springframework.boot.web.servlet.DynamicRegistrationBean<ServletRegistration.Dynamic>
org.springframework.boot.web.servlet.ServletRegistrationBean<T>
- Type Parameters:
- T- the type of the- Servletto register
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ServletContextInitializer,- Ordered
- Direct Known Subclasses:
- DispatcherServletRegistrationBean
public class ServletRegistrationBean<T extends Servlet>
extends DynamicRegistrationBean<ServletRegistration.Dynamic>
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
 RegistrationBean.onStartup(jakarta.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.
- Since:
- 1.4.0
- Author:
- Phillip Webb
- See Also:
- 
Field SummaryFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a newServletRegistrationBeaninstance.ServletRegistrationBean(T servlet, boolean alwaysMapUrl, String... urlMappings) Create a newServletRegistrationBeaninstance with the specifiedServletand URL mappings.ServletRegistrationBean(T servlet, String... urlMappings) Create a newServletRegistrationBeaninstance with the specifiedServletand URL mappings.
- 
Method SummaryModifier and TypeMethodDescriptionprotected ServletRegistration.DynamicaddRegistration(String description, ServletContext servletContext) voidaddUrlMappings(String... urlMappings) Add URL mappings, as defined in the Servlet specification, for the servlet.protected voidconfigure(ServletRegistration.Dynamic registration) Configure registration settings.protected StringReturn a description of the registration.Returns themulti-part configurationto be applied ornull.Return the servlet being registered.Returns the servlet name that will be registered.Return a mutable collection of the URL mappings, as defined in the Servlet specification, for the servlet.voidsetLoadOnStartup(int loadOnStartup) Sets theloadOnStartuppriority.voidsetMultipartConfig(MultipartConfigElement multipartConfig) Set themulti-part configuration.voidsetServlet(T servlet) Sets the servlet to be registered.voidsetUrlMappings(Collection<String> urlMappings) Set the URL mappings for the servlet.toString()Methods inherited from class org.springframework.boot.web.servlet.DynamicRegistrationBeanaddInitParameter, getInitParameters, getOrDeduceName, isAsyncSupported, register, setAsyncSupported, setBeanName, setIgnoreRegistrationFailure, setInitParameters, setNameMethods inherited from class org.springframework.boot.web.servlet.RegistrationBeangetOrder, isEnabled, onStartup, setEnabled, setOrder
- 
Constructor Details- 
ServletRegistrationBeanpublic ServletRegistrationBean()Create a newServletRegistrationBeaninstance.
- 
ServletRegistrationBeanCreate a newServletRegistrationBeaninstance with the specifiedServletand URL mappings.- Parameters:
- servlet- the servlet being mapped
- urlMappings- the URLs being mapped
 
- 
ServletRegistrationBeanCreate a newServletRegistrationBeaninstance with the specifiedServletand URL mappings.- Parameters:
- servlet- the servlet being mapped
- alwaysMapUrl- if omitted URL mappings should be replaced with '/*'
- urlMappings- the URLs being mapped
 
 
- 
- 
Method Details- 
setServletSets the servlet to be registered.- Parameters:
- servlet- the servlet
 
- 
getServletReturn the servlet being registered.- Returns:
- the servlet
 
- 
setUrlMappingsSet 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:
 
- 
getUrlMappingsReturn a mutable collection of the URL mappings, as defined in the Servlet specification, for the servlet.- Returns:
- the urlMappings
 
- 
addUrlMappingsAdd URL mappings, as defined in the Servlet specification, for the servlet.- Parameters:
- urlMappings- the mappings to add
- See Also:
 
- 
setLoadOnStartuppublic void setLoadOnStartup(int loadOnStartup) Sets theloadOnStartuppriority. SeeServletRegistration.Dynamic.setLoadOnStartup(int)for details.- Parameters:
- loadOnStartup- if load on startup is enabled
 
- 
setMultipartConfigSet themulti-part configuration.- Parameters:
- multipartConfig- the multipart configuration to set or- null
 
- 
getMultipartConfigReturns themulti-part configurationto be applied ornull.- Returns:
- the multipart config
 
- 
getDescriptionDescription copied from class:RegistrationBeanReturn a description of the registration. For example "Servlet resourceServlet"- Specified by:
- getDescriptionin class- RegistrationBean
- Returns:
- a description of the registration
 
- 
addRegistrationprotected ServletRegistration.Dynamic addRegistration(String description, ServletContext servletContext) - Specified by:
- addRegistrationin class- DynamicRegistrationBean<ServletRegistration.Dynamic>
 
- 
configureConfigure registration settings. Subclasses can override this method to perform additional configuration if required.- Overrides:
- configurein class- DynamicRegistrationBean<ServletRegistration.Dynamic>
- Parameters:
- registration- the registration
 
- 
getServletNameReturns the servlet name that will be registered.- Returns:
- the servlet name
 
- 
toString
 
-