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

<mvc:view-resolvers> does not reliably find declared ContentNegotiationManager

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.1.7, 4.2.1
    • Fix Version/s: 4.1.9, 4.2.3
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      In the following, does the ContentNegotiatingViewResolver created by <mvc:view-resolvers> automatically get set with the mvcContentNegotiationManager? My tests are telling me not.

      	<mvc:annotation-driven
      		content-negotiation-manager="mvcContentNegotiationManager" />
      
      	<!-- View resolver chain -->
      	<mvc:view-resolvers>
      		<mvc:content-negotiation use-not-acceptable="true" />
      		<mvc:bean-name />
      		<mvc:tiles />
      		<bean class="rewardsonline.accounts.JsonViewResolver" />
      	</mvc:view-resolvers>
      
      	<bean id="mvcContentNegotiationManager"
      		class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
      		<property name="ignoreAcceptHeader" value="true" />
      		<property name="defaultContentType" value="text/html" />
      	</bean>
      

      Running this as a servlet app does work, but my MockMvc test fails trying to generate JSON.

      If I explicitly get the ContentNegotiatingViewResolver when the test starts and manually set the ContentNegotiationManager to mvcContentNegotiationManager, it works.

      I would expect the CNVR created using <mvc:view-resolvers/> to be initialised with the same ContentNegotiationManager that was specified to <mvc:annotation-driven>.

        Attachments

          Activity

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              chapmanp Paul Chapman
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 44 weeks ago