@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; }