Scrivio Interview library
InternalsFoundations6 min read · updated 12 November 2026

Which HandlerExceptionResolver implementations does Spring MVC register by default, in what order, and what does each handle?

Spring MVC registers three resolvers by default, tried in this order: ExceptionHandlerExceptionResolver, which calls our @ExceptionHandler methods in the controller and in @ControllerAdvice classes; ResponseStatusExceptionResolver, which handles ResponseStatusException and exceptions annotated with @ResponseStatus; and DefaultHandlerExceptionResolver, which maps Spring MVC's own exceptions to statuses such as 405 and 415. They sit inside a HandlerExceptionResolverComposite, the first one that returns a ModelAndView (even an empty one) wins, and if none handles the exception it goes to the servlet container, where Spring Boot's /error handling writes the response.

Why this question is asked

Most of us write @ExceptionHandler methods without ever thinking about what calls them. But when an exception produces a 405 we did not expect, or a custom handler is ignored, or a response looks like Boot's default JSON instead of ours, the answer is always in the resolver chain. Interviewers ask this question because it shows whether we understand how Spring MVC turns an exception into a response, and it is the foundation for every follow-up about custom resolvers. In this answer, we will recap what a resolver is, go through the three defaults in order with an example of each, see how the chain stops, follow an exception that nobody handles to /error, and then see where a custom resolver fits.

1A Quick Recap of HandlerExceptionResolver

When a controller method throws, the exception does not go straight to the client. The DispatcherServlet, the front controller that routes every request to a handler, catches it and asks a list of HandlerExceptionResolver objects what to do. The interface has one method, resolveException, which receives the request, the response, the handler that failed and the exception. A resolver either returns a ModelAndView, meaning I have dealt with it, or returns null, meaning not mine, ask the next one.

A ModelAndView normally names a view to render, but an empty one has a special meaning: the resolver has already written the response itself, for example by writing a JSON body or calling response.sendError(), and nothing more should be rendered. That detail is why the chain can stop even when no view is involved.

2The Three Default Resolvers, in Order

When we use Spring Boot, or @EnableWebMvc in plain Spring, the configuration registers one bean called handlerExceptionResolver of type HandlerExceptionResolverComposite, which holds the three defaults in a fixed order. The first is ExceptionHandlerExceptionResolver. It looks for an @ExceptionHandler method that matches the exception, first in the controller that threw it and then in @ControllerAdvice classes, and invokes it with the same argument resolution and return value handling as a normal controller method. That is why an @ExceptionHandler can return a ProblemDetail or a ResponseEntity.

The second is ResponseStatusExceptionResolver. It handles a ResponseStatusException thrown in code, such as new ResponseStatusException(HttpStatus.NOT_FOUND, "No such order"), and any exception class annotated with @ResponseStatus, and it also looks at the cause chain for such an annotation. It applies the status, usually by calling response.sendError() with the reason.

The third is DefaultHandlerExceptionResolver. It knows Spring MVC's own exceptions and maps each to the right status: HttpRequestMethodNotSupportedException to 405, HttpMediaTypeNotSupportedException to 415, HttpMediaTypeNotAcceptableException to 406, MissingServletRequestParameterException, MethodArgumentNotValidException and HttpMessageNotReadableException to 400, and NoHandlerFoundException or NoResourceFoundException to 404. It sets the status with sendError() and returns an empty ModelAndView.

The default resolver chain
OrderResolverHandlesExample
1ExceptionHandlerExceptionResolver@ExceptionHandler in controller, then adviceOrderNotFound -> our 404 JSON
2ResponseStatusExceptionResolverResponseStatusException, @ResponseStatus@ResponseStatus(CONFLICT) -> 409
3DefaultHandlerExceptionResolverSpring MVC's standard exceptionsPOST on a GET-only URL -> 405
noneServlet container + Boot /erroreverything leftNullPointerException -> 500
The first resolver that returns a ModelAndView ends the search.

3Watching the Chain Decide

A small controller shows each resolver at work. Each request ends with a different resolver.

Java
@ResponseStatus(HttpStatus.CONFLICT)
class DuplicateOrderException extends RuntimeException {}
class OrderNotFoundException extends RuntimeException {}
@RestController
class OrderController {
@GetMapping("/orders/{id}")
Order get(@PathVariable long id) { throw new OrderNotFoundException(); }
@PostMapping("/orders")
Order create() { throw new DuplicateOrderException(); }
@ExceptionHandler(OrderNotFoundException.class)
ProblemDetail notFound() { return ProblemDetail.forStatus(404); }
}
// GET /orders/1 -> 404 with our ProblemDetail (resolver 1: @ExceptionHandler)
// POST /orders -> 409 (resolver 2: @ResponseStatus)
// PUT /orders/1 -> 405, Allow: GET (resolver 3: HttpRequestMethodNotSupportedException)
// GET /orders/x -> 400 (resolver 3: type mismatch on the path variable)

Notice the order matters. If we add an @ExceptionHandler(DuplicateOrderException.class) to an advice, resolver 1 handles it first, and the @ResponseStatus annotation on the class is never consulted. In the same way, an advice that handles HttpRequestMethodNotSupportedException, or one that extends ResponseEntityExceptionHandler (which handles all of Spring MVC's standard exceptions), takes over from DefaultHandlerExceptionResolver and can return a problem detail body instead of a bare status.

4When Nobody Handles the Exception

If all three return null, the DispatcherServlet rethrows the exception. It travels out through the filters to the servlet container, Tomcat by default in Spring Boot. Spring Boot registers an error page with the container for every error, pointing at /error. So the container sets the status to 500 and makes an internal ERROR dispatch, a second pass through the application for the same request, to /error. There Boot's BasicErrorController builds the response: JSON for API clients and the Whitelabel HTML page for browsers.

The same /error path is used when a resolver only set a status with sendError(), as DefaultHandlerExceptionResolver does. The container sees the error status and dispatches to /error to render a body. That is why a 405 from a Boot app has Boot's familiar JSON body with timestamp, status, error and path, although no controller ever returned it.

Step throughAn exception that no resolver handles
DispatcherServletResolver chainTomcatBasicErrorController
resolveException(NullPointerException)
null from all three resolvers
rethrow the exception
status 500, look up the error page
ERROR dispatch to /error
JSON or Whitelabel HTML

6 messages in order. Play them, or step through them one at a time.

Boot's error handling is a second dispatch inside the same request.

5Where Spring Boot Adds Its Own Resolver

There is one more resolver in a Boot application that people rarely notice. DefaultErrorAttributes, the bean that collects the data shown on /error, also implements HandlerExceptionResolver with the highest precedence. It runs before the composite, stores the exception in a request attribute so /error can report it later, and always returns null so the real resolvers still run. It is a good example of a resolver that observes without deciding.

The DispatcherServlet sorts all HandlerExceptionResolver beans by their order. The composite has order 0, DefaultErrorAttributes has the highest precedence, and any other resolver bean without an explicit order gets the lowest precedence, so it runs after the three defaults.

6Follow-up questions

Where would a custom HandlerExceptionResolver fit, and how do you set its order?

A custom resolver is a bean that the DispatcherServlet sorts together with the composite. We give it a position by implementing Ordered or by extending AbstractHandlerExceptionResolver and calling setOrder. With a negative order it runs before the defaults and sees every exception, so it must return null for anything it should not handle; with no order it runs after them and only sees exceptions they left alone. To place it inside the default list instead, we implement WebMvcConfigurer.extendHandlerExceptionResolvers and insert it at the index we want. Overriding configureHandlerExceptionResolvers with a non-empty list replaces the defaults entirely, which is rarely what we want.

Why does a 405 from Spring Boot have a JSON body when DefaultHandlerExceptionResolver only sets a status?

Because DefaultHandlerExceptionResolver calls response.sendError(405), and the servlet container then performs an error dispatch to /error, where BasicErrorController writes Boot's JSON body. If we want our own body, we handle the exception in an advice, for example by extending ResponseEntityExceptionHandler, so resolver 1 writes the response and the error dispatch never happens.

Is @ResponseStatus on an exception a good idea?

It is fine for simple cases, but it ties the HTTP status to the exception class and produces a response without a structured body. In larger applications we usually prefer one advice that maps exceptions to problem details, so the status and body are decided in one place and the domain exceptions stay free of web annotations.

7Conclusion

In this answer, we saw that Spring MVC asks a chain of HandlerExceptionResolvers what to do with an exception. By default the composite holds ExceptionHandlerExceptionResolver for @ExceptionHandler methods in controllers and advice, ResponseStatusExceptionResolver for ResponseStatusException and @ResponseStatus, and DefaultHandlerExceptionResolver for Spring MVC's own exceptions such as 405 and 415. The first resolver that returns a ModelAndView, even an empty one, ends the search; anything left goes to the container, which dispatches to /error where Boot's BasicErrorController writes the response. Boot's DefaultErrorAttributes runs first only to record the exception.

What to say in the interviewAbout 80 seconds aloud

Open with

When a handler throws, the DispatcherServlet asks its HandlerExceptionResolvers in order, and the first one that returns a ModelAndView, even an empty one meaning the response is already written, ends the search.

Then, if they want more

By default there are three, held in a HandlerExceptionResolverComposite. First, ExceptionHandlerExceptionResolver, which finds a matching @ExceptionHandler method, first in the controller and then in @ControllerAdvice classes, and invokes it like a controller method, so it can return a ProblemDetail or ResponseEntity. Second, ResponseStatusExceptionResolver, which handles ResponseStatusException and exceptions annotated with @ResponseStatus.

Third, DefaultHandlerExceptionResolver, which maps Spring MVC's own exceptions: method not supported to 405, unsupported media type to 415, not acceptable to 406, missing parameters and unreadable bodies to 400, no handler to 404. It calls sendError and returns an empty ModelAndView.

If none of them handles the exception, it propagates to the container, and Spring Boot's error page mapping forwards to /error, where BasicErrorController returns JSON or the Whitelabel page. The same /error dispatch renders the body after a sendError. In Boot, DefaultErrorAttributes is also a resolver with highest precedence, but it only stores the exception and returns null. A custom resolver gets its position through Ordered or setOrder, or through extendHandlerExceptionResolvers.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Which HandlerExceptionResolver implementations does Spring MVC register by default, in...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/8a22bc7c91/