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 558749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:09:52+00:00 2026-05-13T12:09:52+00:00

I was reading the Spring 3.0 Documentation and Blog Posts (followups) on how to

  • 0

I was reading the Spring 3.0 Documentation and Blog Posts (followups) on how to create REST style services with Spring MVC but I can’t find any working example on how to use the ContentNegotiatingViewResolver. I have a test controller like this

@Controller
public class IndexController implements Serializable
{
    @RequestMapping("/index")
    public ModelAndView index()
    {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }   
}

and tried to use something like this

<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="mediaTypes">
        <map>
            <entry key="html" value="text/html" />
            <entry key="xml" value="text/xml" />
            <!--
                <entry key="json" value="application/json"/>
            -->
        </map>
    </property>
    <property name="defaultContentType"><value>text/html</value></property>
    <property name="defaultViews">
        <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
            <property name="marshaller">
                <bean class="org.springframework.oxm.xstream.XStreamMarshaller" />
            </property>
        </bean>
    </property>
    <property name="viewResolvers">
        <list>
            <bean
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/views/pages/" />
                <property name="suffix" value=".jsp" />
            </bean>
        </list>
    </property>
</bean>

trying to resolve the views according to the extension in the URL (I want to support html, .xml and .json). The .html view works (showing the correct JSP view, too) but nothing else I tried for getting JSON and XML up and running seems to work (setting the defaultViews property was just one of the things I tried). There doesn’t seem to be that much reading material either. Does anybody have experience or examples?

  • 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-05-13T12:09:53+00:00Added an answer on May 13, 2026 at 12:09 pm

    I believe you’re problem is that the content-type of XML is not text/xml, it’s application/xml. You’ll find that MarshallingView will not accept a content type of text/xml.

    What ContentNegotiatingViewResolver does is consult each of its views, asking them if they’ll accept the content type that was resolved from the request. For each content type you want to support, you need a view with a matching contentType property.

    You can either change the content type in the mediaTypes property, or you can override contentType property of MarshallingView to be text/xml.

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

Sidebar

Related Questions

I'm reading Spring WebFlow documentation, but I don't understand what can i do with
I am learning Spring-MVC in my first project here. After reading the documentation on
I was reading Spring 3.0 documentation and I came to the sentence - Annotation
I'm refreshing my Spring knowledge, reading the reference documentation for spring 3.1. Last time
after reading the H2 documentation , I wrote this simple application to create a
I'm reading the jQuery load documentation and it mentions that I can use load
I am reading a documentation, but it is not specified how to encode url's.
I am reading spring through its official documentation and at one place I came
after reading the Zend documentation and some posts here I could not figure out
I'm familiar with Regex itself, but whenever I try to find any examples or

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.