Spring MVC - Default HandlerExceptionResolvers Ordering MCQ
0/13
0✓
0✗
1. Which HandlerExceptionResolver implementations are registered by default in Spring MVC Java config, in the correct order?
Why: By default, the delegates are ExceptionHandlerExceptionResolver, ResponseStatusExceptionResolver and DefaultHandlerExceptionResolver, in exactly this order. SimpleMappingExceptionResolver is not active by default.
2. How are the default exception resolvers exposed to DispatcherServlet?
Why: Only one HandlerExceptionResolverComposite is registered by default. It has order 0 and contains the default resolvers as its delegates.
3. A HandlerExceptionResolverComposite contains several delegate resolvers. How are the delegates ordered?
Why:DispatcherServlet sorts its own list of resolvers, but the delegates inside a composite are not sorted. They are tried in the order they were added.
4. Resolver A implements Ordered with order 5. Resolver B does not implement Ordered. Resolver C implements Ordered with order -2. The default composite has order 0. In which order does DispatcherServlet try them?
Why: Resolvers are sorted by order value in ascending order. A resolver that does not implement Ordered gets the lowest precedence (Integer.MAX_VALUE), so it goes last.
5. An exception is thrown while handling a request. Which resolver in the sorted list handles it?
Why:DispatcherServlet goes through the resolvers in order. The first one that returns a non-null ModelAndView wins and the rest are skipped. If none of them handles the exception, it stays unhandled.
6. Which class registers the default exception resolvers when you use the MVC Java config?
Why:WebMvcConfigurationSupport is the main class behind the MVC Java config and @EnableWebMvc. It creates the default exception resolvers.
7. The default resolver bean is named handlerExceptionResolver. What happens if you register this bean in your configuration?
@Bean
public HandlerExceptionResolver handlerExceptionResolver() {
return new MyResolver();
}
Why: The bean name is taken from the factory method name. A bean with exactly the same name overrides the default one.
8. Which of these HandlerExceptionResolver implementations is not active by default?
Why:SimpleMappingExceptionResolver must be registered by the application. The other three are part of the default resolvers.
9. Which resolver is responsible for the @ExceptionHandler methods of a controller?
Why:ExceptionHandlerExceptionResolver calls the controller method whose declared exception type matches the thrown exception.