Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15248

Allow configuring the ContentNegotiationManager in MockMVC standalone controller setup

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.6, 5.0 M4
    • Fix Version/s: 4.3.7, 5.0 RC1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            rstoya05-aop Rossen Stoyanchev
            Reporter:
            olivergierke Oliver Drotbohm
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 1 week, 4 days ago