title: How do I create a 404 controller using Spring Boot?
body: <p>I'd like to return a custom 404 error using SpringBoot, but I'd like to be able to add some server-side logic to it, not just serve a static page.</p>
  
  <p><strong>1. I switched off the default whitelabel page in <code>application.properties</code></strong></p>
  
  <p><code>error.whitelabel.enabled=false</code></p>
  
  <p><strong>2. I added a Thymeleaf error.html under <code>resources/templates</code></strong></p>
  
  <p>This works by the way. The page is served, but no controller is called. </p>
  
  <p><strong>3. I created a class <code>Error</code> to be the "Controller"</strong></p>
  
  <pre><code>package com.noxgroup.nitro.pages;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  @Controller
  @RequestMapping("/error")
  public class Error {
  
      @ExceptionHandler
      public String index() {
          System.out.println("Returning Error");
          return "index";
      }
  
  }
  </code></pre>
  
  <p>Unfortunately, I'm not seeing <code>Returning Error</code> printed anywhere in the console.</p>
  
  <p>I'm using the Embedded Tomcat with Spring Boot. I've seen various options, non of which seem to work including using @ControllerAdvice, removing the RequestMapping, etc. Neither work for me.</p>