Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9317409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:52:17+00:00 2026-06-19T02:52:17+00:00

We develop a standard Java web application using Spring MVC, and have recently tried

  • 0

We develop a standard Java web application using Spring MVC, and have recently tried to upgrade from 3.0.6 to 3.2.0. Nearly of all our servlet responses are JSP or Json views, but there are some that are pdf requests, with extension ‘pdf’.

In Spring 3.0.6
we had this set up, taken from the Spring MVC documentation.

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
  <entry key="pdf" value="application/pdf"/>
  <entry key="html" value="text/html"/>
  <entry key="json" value="application/json"/>
</map>

which worked fine, in combination with an XMLViewResolver.

After updating to 3.2.0, there is a failure :

Error creating bean with name' org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0' defined in class path  resource [dispatcher-test-servlet.xml]: Invocation of init method failed; nested exception is 

java.lang.ClassCastException: java.lang.String cannot be cast to                   org.springframework.http.MediaType'

After investigating the docs and some blogs, this configuration seems to work:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
   <property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
    <list>
    <!-- These are evaluated in order -->
    <!-- Is there a media type based on suffix? -->
<bean                  class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
    <map>
<entry key="html" value="text/html" />
<entry key="json" value="application/json" />
<entry key="pdf" value="application/pdf" />
</map>
</constructor-arg>
</bean>
<!-- Else use request header -->
<bean
            class="org.springframework.web.accept.HeaderContentNegotiationStrategy">

</bean>
</list>
</constructor-arg>
</bean>
</property>

But, we have tried running the new Spring MVC test framework using this configuration, and get the ClassCast exception again, so it seems the test framework is not initialising the beans in the same way as when the application runs…
Does anyone have a clear explanation of how to configure the ContentNegotiatingViewResolver in Spring 3,2 in a robust fashion?
Thanks

Richard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:52:18+00:00Added an answer on June 19, 2026 at 2:52 am

    With spring 3.2 it is better resolved using ContentNegotiationManager. It is working for me. You could use the static field like org.springframework.http.MediaType.APPLICATION_JSON_VALUE to mention the mediatype. check the following code:

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
            <property name="contentNegotiationManager">
                <bean class="org.springframework.web.accept.ContentNegotiationManager">
                    <constructor-arg>
                        <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
                            <constructor-arg>
                                <map>
                                    <entry key="json">
                                        <util:constant static-field="org.springframework.http.MediaType.APPLICATION_JSON_VALUE" />
                                    </entry>
                                    <entry key="xml">
                                        <util:constant static-field="org.springframework.http.MediaType.APPLICATION_XML_VALUE" />
                                    </entry>
                                </map>
                            </constructor-arg>
                        </bean>
                    </constructor-arg>
                </bean>
            </property>
    
            <property name="defaultViews">
                <list>
                   <!-- default views -->
                </list>
            </property>
    
        </bean>
    

    For this you have to use util schema in your dispatcher-servlet.xml file, i.e. xmlns:util="http://www.springframework.org/schema/util" and schema location http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm have a lot of time using hibernate (JPA) in java, but i recently
I'm planning to develop a Web/cloud application using python which does the following, 1.
i'm new in java and recently started to develop an simple application. For the
We're developing a data heavy modular web application stack with java but have little
I am trying to develop the XMPP Gateway which can send/receive from standard XMPP
I Develop a Form Designer, also develop some custom control that inherit from standard
I develop a web by using ASP.NET MVC2. Creating the cookie in the background.
I develop a Java application with 4 tiers : database (MySQL), persistence (JPA), business
I have Standard version of eclipse Galileo. Now I want to develop enterprise applications
I'm trying to develop a new application based on the standard Utility template, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.