With Spring 5.0, there are three ways to configure DispatcherServlet programmatically, by implementing or extending any of the following three classes:
- WebAppInitializer interface
- AbstractDispatcherServletInitializer abstract class
- AbstractAnnotationConfigDispatcherServletInitializer abstract class
We will use the AbstractDispatcherServletInitializer class, as it is the preferred approach for applications that use Java-based Spring configuration. It is preferred because it allows us to start a servlet application context, as well as a root application context.
We need to create the following class to configure DispatcherServlet:
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; ...