Class ServletRegistrationBean<T extends Servlet>

Type Parameters:
T - the type of the Servlet to 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:
  • Constructor Details

    • ServletRegistrationBean

      public ServletRegistrationBean()
      Create a new ServletRegistrationBean instance.
    • ServletRegistrationBean

      public ServletRegistrationBean(T 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
    • ServletRegistrationBean

      public ServletRegistrationBean(T servlet, boolean alwaysMapUrl, String... urlMappings)
      Create a new ServletRegistrationBean instance with the specified