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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Complete
    • 4.1.7, 4.2.1
    • 4.1.9, 4.2.3
    • Web
    • None
    • true

    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

            rstoya05-aop Rossen Stoyanchev
            chapmanp Paul Chapman
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3 years, 47 weeks, 2 days ago