Settings that can be made to the MVC infrastructure through WebMvcConfigurerAdapter.configureContentNegotiation(…) can't be easily replicated to MockMvcBuilders.standaloneSetup(…) as the method to set the ContentNegotiationManager is protected. Even if it was public, the API to interact with the manager directly is way different than the one you get through the adapter API.
That effectively means that to replicate the web framework behavior I get through my normal web configuration in standalone controller mode I have to repeat a lot of configuration code which even needs to look different than my normal configuration.
Is there maybe a way to derive the setup ffrom handing over a configration class that extends WebMvcConfigurerAdapter so that the production configuration can simply be reused?
To complete the picture, here's the situation that caused the issue in the first palce. The addition of Spring Data Redis transitively pulled in spring-context-support into the classpath of a project. That in turn causes Spring MVC all of a sudden to resolve URI endings to media types (due to the presence of mime.types on the classpath). This can now now be disabled in the production path by configuring the ContentNegotiationManager, but the tests for standalone tests still now run into that file erroneously being considered.
Affects: 4.3.6, 5.0 M4
The text was updated successfully, but these errors were encountered:
The protected modifier was not intentional and wrong from the start it seems. I have corrected it in both master and 4.3.x.
I wonder if there are any more reasons for taking a WebMvcConfigurer directly? We could do that although it would be a complete alternative to the individual methods, and I'm wondering if we do need it.