Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring the ContentNegotiationManager in MockMVC standalone controller setup [SPR-15248] #19813

Closed
spring-issuemaster opened this issue Feb 13, 2017 · 1 comment

Comments

@spring-issuemaster
Copy link
Collaborator

commented Feb 13, 2017

Oliver Drotbohm opened SPR-15248 and commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 23, 2017

Rossen Stoyanchev commented

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.