title: How to intercept "global" 404s on embedded Tomcats in spring-boot
body: <p>I´m having a rather strange issue with the embedded tomcat that comes with spring-boot, specifically with it´s error handling.</p>
  
  <p>Basicly, I´m trying to handle all exceptions via a custom handler.
  Long story short: It works for everything except 404. Are those handled via any other mechanism and not Exceptions?</p>
  
  <p>All other status codes I tested with call my custom Resolver, only 404s present me with the default Tomcat 404 page. More specifically, 404s thrown outside of a controller, e.g. a request for /teXst if there are only controllers for /test registered. On such exceptions I don´t get my Resolver called and only see the default Tomcat HTTP Status 404 page.</p>
  
  <p>Any idea what might get in my way?
  Here is how I set up my Resolver</p>
  
  <pre><code>public class GlobalExceptionResolver extends AbstractHandlerExceptionResolver {
          @Override
          public int getOrder() {
              return Integer.MIN_VALUE;
          }
  
          @Override
          protected boolean shouldApplyTo(HttpServletRequest request, Object handler) {
              return true;
          }
  
          @Override
          protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
       // my stuff ending with returning an instance of ModelAndView
      }
  </code></pre>
  
  <p>To get all default Spring-Boot Error handling out of the way I annotate with</p>
  
  <pre><code>@EnableAutoConfiguration(exclude = org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.class)
  </code></pre>
  
  <p>which leaves me with the default Tomcat Error pages for 404, 500 and so on, and finally set up my custom handler with</p>
  
  <pre><code>@Bean
  public WebMvcConfigurerAdapter adapter() {
      return new WebMvcConfigurerAdapter() {
          @Override
          public void configureHandlerExceptionResolvers(List&lt;HandlerExceptionResolver&gt; exceptionResolvers) {
              exceptionResolvers.add(new GlobalExceptionResolver());
          }
  </code></pre>
  
  <p>As said, this setup works fine for all exceptions except HTTP status 404. Any idea what mechanism creates these pages and why my exception resolver is not called? This is on Spring Boot 1.2.5.RELEASE using Spring MVC 4.1.7.RELEASE and embedded Tomcat 8.0.23</p>