AbstractAnnotationConfigDispatcherServletInitializer is a base class to initialize Spring application in Servlet container environment. It's an extension of WebApplicationInitializer. The subclasses are supposed to provide the classes annotated with @Configuration, Servlet config classes and DispatcherServlet mapping pattern.
@Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{AppConfig.class}; }
@Override protected String[] getServletMappings() { return new String[]{"/"}; }
@Override protected DispatcherServlet createDispatcherServlet(WebApplicationContext wac) { DispatcherServlet ds = new DispatcherServlet(wac); //setting this flag to true will throw NoHandlerFoundException instead of 404 page // removed in spring 7 ds.setThrowExceptionIfNoHandlerFound(true); return ds; } }
DispatcherServlet#setDetectAllHandlerExceptionResolvers(false) will allow to register only one HandlerExceptionResolver bean with name handlerExceptionResolver