Announcement Announcement Module
Collapse
No announcement yet.
How to use ContentNegotiationStrategy in Spring MVC3.2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use ContentNegotiationStrategy in Spring MVC3.2

    Hi together,
    I used to config ContentNegotiatingViewResolver in Spring3.1 with inject mediaTypes as
    Code:
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">  
            <property name="mediaTypes">
                <map>  
                    <entry key="json" value="application/json"/>
                </map>  
             </property>  
             <property name="defaultViews">
    		<list>
    			<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
    		</list>
    	</property>
    </bean>
    but in spring3.2 setMediaTypes is deprecated in ContentNegotiatingViewResolver and suggest to use setContentNegotiationManager.
    Furthermore, if I use mediaTypes in spring3.2 it will thorw a ClassCastException in its parent class MappingMediaTypeFileExtensionResolver

    Code:
    java.lang.ClassCastException: java.lang.String cannot be cast to org.springframework.http.MediaType
    	at org.springframework.web.accept.MappingMediaTypeFileExtensionResolver.<init>(MappingMediaTypeFileExtensionResolver.java:56)
    	at org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.<init>(AbstractMappingContentNegotiationStrategy.java:42)
    	at org.springframework.web.accept.PathExtensionContentNegotiationStrategy.<init>(PathExtensionContentNegotiationStrategy.java:74)
    	at org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy.<init>(ServletPathExtensionContentNegotiationStrategy.java:47)
    	at org.springframework.web.accept.ContentNegotiationManagerFactoryBean.afterPropertiesSet(ContentNegotiationManagerFactoryBean.java:166)
    	at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.afterPropertiesSet(ContentNegotiatingViewResolver.java:270)
    I don't know how to declare a contentNegotiationManager and inject into ContentNegotiatingViewResolver or how to use ContentNegotiationStrategy in Spring MVC3.2

    Any ideas?
    Thanks!

  • #2
    Check out this post: http://forum.springsource.org/showth...538#post433538

    Comment


    • #3
      thank you very much,it works!

      Comment

      Working...
      X