What are the advantages of using a ContentNegotiatingViewResolver?

ContentNegotiatingViewResolver is a special Spring MVC view resolver that doesn't resolve views itself but instead delegates to other configured view resolvers based on the format the client is requesting. It picks the best matching view — JSON, XML, or HTML — by inspecting the request's Accept header, URL extension, or a format parameter.

Key Points

Example

A single /report/{id} endpoint could return an HTML report page for browsers by default, but an automated client sending Accept: application/json for the same URL would get a JSON representation instead.

Interview Tip

A concise interview answer is

ContentNegotiatingViewResolver picks the right view format — JSON, XML, or HTML — based on what the client requests, usually via the Accept header. It's useful when the same endpoint needs to serve multiple response formats without duplicating controller logic, though in pure REST APIs, @RestController with Jackson usually replaces this need.

Last updated: 16 July 2026

Previous question: How does InternalResourceViewResolver work in Spring MVC?

Next question: How are interceptors used in Spring MVC?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions