Question: how can I handle exceptions thrown in MVC endpoints in management context?
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);
}
}
With the current configuration, I receive 500 instead of 404. I tried usual approaches for exception handling like ControllerAdvice, ExceptionHandler methods, etc. No success.
I also found CompositeHandlerExceptionResolver in EndpointWebMvcChildContextConfiguration which is responsible for exception handling. I tried to define my own HandlerExceptionResolver bean but it cannot find my resolver in management context.