title: Make simple servlet filter work with @ControllerAdvice
body: <p>I've a simple filter just to check if a request contains a special header with static key - no user auth - just to protect endpoints. The idea is to throw an <code>AccessForbiddenException</code> if the key does not match which then will be mapped to response with a class annotated with <code>@ControllerAdvice</code>. However I can't make it work. My <code>@ExceptionHandler</code> isn't called.</p>
  
  <p><strong>ClientKeyFilter</strong></p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Value
  import org.springframework.stereotype.Controller
  
  import javax.servlet.*
  import javax.servlet.http.HttpServletRequest
  
  @Controller //I know that @Component might be here
  public class ClientKeyFilter implements Filter {
  
    @Value('${CLIENT_KEY}')
    String clientKey
  
    public void init(FilterConfig filterConfig) {}
  
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
      req = (HttpServletRequest) req
      def reqClientKey = req.getHeader('Client-Key')
      if (!clientKey.equals(reqClientKey)) {
        throw new AccessForbiddenException('Invalid API key')
      }
      chain.doFilter(req, res)
    }
  
    public void destroy() {}
  }
  </code></pre>
  
  <p><strong>AccessForbiddenException</strong></p>
  
  <pre><code>public class AccessForbiddenException extends RuntimeException {
    AccessForbiddenException(String message) {
      super(message)
    }
  }
  </code></pre>
  
  <p><strong>ExceptionController</strong></p>
  
  <pre><code>@ControllerAdvice
  class ExceptionController {
    static final Logger logger = LoggerFactory.getLogger(ExceptionController)
  
    @ExceptionHandler(AccessForbiddenException)
    public ResponseEntity handleException(HttpServletRequest request, AccessForbiddenException e) {
      logger.error('Caught exception.', e)
      return new ResponseEntity&lt;&gt;(e.getMessage(), I_AM_A_TEAPOT)
    }
  }
  </code></pre>
  
  <p>Where I'm wrong? Can simple servlet filter work with spring-boot's exception mapping?</p>