Running the application however had a few problems. We had been using a ContentNegotiatingViewResolver to return a PDF view of certain webpages when the URL ends in ',pdf'. After updating, all webpages were trying to return pdf content, even without the suffix, or we would get a ClassCastException ('String cannot be converted to Media Type').
Content negotiation is not trivial to sort out, and it seems in 3.2 Spring have tried to make it more flexible, configurable and reusable, by introducing ContentNegotiationStrategy implementations which resolve views using different policies. This is documented here, but at least to me the documentation is a bit cryptic and hard to understand.
Here is how we fixed this:
Note that there are two strategies:PathExtensionContentNegotiationStrategy and HeaderContentNegotiationStrategy. These are evaluated in the order they appear in the list.
- First of all, if the request URL has a suffix, the path extension strategy will try to find a view resolver that can deal with that suffix, based on the media type mappings supplied to the constructor. If a match is found, no more strategies are evaluated
- If there was no suffix, or there is no view, the HeaderContentNegotiationStrategy will examine the request headers, and match up a view.
- Views are then evaluated to a 'best match' as in earlier versions of Spring.
I'm sure people have different strategies for handling content negotiation; upgrading to 3.2 did break our current web app but hopefully this solution will help others.