DispatcherServlet
is the gateway to any Spring MVC application. Inherited from javax.servlet.http.HttpServlet
, it is typically configured declaratively in the web.xml
file. While you can have multiple definitions of DispatcherServlet
with unique URL patterns, most Spring MVC applications only have single DispatcherServlet
with the context-root
URL(/
), that is, all requests coming to that domain will be handled by DispatcherServlet
.
Starting from Servlet 3.0, in addition to declarative configuration in the web.xml
file, DispatcherServlet
can be configured programmatically by implementing or extending either of these three support classes provided by Spring:
The
WebAppInitializer
interfaceThe
AbstractDispatcherServletInitializer
abstract classThe
AbstractAnnotationConfigDispatcherServletInitializer
abstract class
The following code listing demonstrates how to implement a WebAppInitializer
directly in your application:
public class ApplicationInitializer implements...