As you know, in XML, the way to configure this is:
404 /my-custom-page-not-fo
The solution proposed in comments above really works:
@Override protected void customizeRegistration(ServletRegistration.Dynamic registration) { registration.setInitParameter("throwExceptionIfNoHandlerFound", "true"); }