A ViewResolver in Spring MVC maps the logical view name returned by a controller to an actual renderable view, and Spring ships several implementations for different templating and response technologies.
Key Points: • InternalResourceViewResolver resolves JSP views by applying a configured prefix and suffix to the view name. • ThymeleafViewResolver and FreeMarkerViewResolver integrate their respective template engines as the rendering layer. • XmlViewResolver and BeanNameViewResolver resolve views defined as Spring beans, either in an XML file or by matching the view name to a bean name. • MappingJackson2JsonView and MappingJackson2XmlView render the model directly as JSON or XML instead of an HTML template. • Multiple resolvers can be chained with an order property, so Spring falls through resolvers until one produces a match.
Example: A traditional Spring MVC app serving JSPs under /WEB-INF/views/ with a .jsp suffix would configure an InternalResourceViewResolver, while a REST-style endpoint returning a Map would rely on MappingJackson2JsonView to serialize it straight to JSON.
Interview Tip: A concise interview answer is:
"Spring MVC has a ViewResolver interface with several implementations depending on the view technology — InternalResourceViewResolver for JSP, ThymeleafViewResolver or FreeMarkerViewResolver for template engines, and Jackson-based view classes for JSON or XML output. You can even chain multiple resolvers with an order so Spring tries each until one resolves the view name."