title: Spring Boot Actuator Management Endpoint Exception Handling
body: <p>Question: how can I handle exceptions thrown in MVC endpoints in management context?</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyMvcEndpoints extends EndpointMvcAdapter {
      @ResponseBody
      @RequestMapping(method = GET, value = "/foo", produces = APPLICATION_JSON_VALUE)
      public Foo foo() {
          throw new FooNotFound("Foo Not Found!");
      }
  }
  
  @ResponseStatus(value = HttpStatus.NOT_FOUND)
  public class FooNotFound extends RuntimeException {
      public NotFoundException(String message){
          super(message);
      }
  }
  </code></pre>
  
  <p>With the current configuration, I receive <code>500</code> instead of <code>404</code>. I tried usual approaches for exception handling like ControllerAdvice, ExceptionHandler methods, etc. No success.<br>
  I also found <code>CompositeHandlerExceptionResolver</code> in <code>EndpointWebMvcChildContextConfiguration</code> which is responsible for exception handling. I tried to define my own <code>HandlerExceptionResolver</code> bean but it cannot find my resolver in management context.</p>