Это то, что @ControllerAdvice делает в Spring MVC
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler({NoHandlerFoundException.class})
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public void handleNotFound(HttpSession session, HttpServletRequest req, HttpServletResponse httpServletResponse, Exception ex) {
}
}
Также добавьте эту строку в ваш WebApplicationInitializer
public class CCPMWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
....
DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext);
dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
...
}