Results 1 to 3 of 3

Thread: How to use ContentNegotiationStrategy in Spring MVC3.2

  1. #1
    Join Date
    Jan 2013
    Posts
    11

    Default 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. #2
    Join Date
    Mar 2007
    Posts
    128

  3. #3
    Join Date
    Jan 2013
    Posts
    11

    Default

    thank you very much,it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •