Results 1 to 2 of 2

Thread: Spring mvc configuration JSON

  1. #1
    Join Date
    Jan 2011
    Posts
    3

    Default Spring mvc configuration JSON

    I would know how works the configuration about Spring MVC rest services that returns JSON.

    I have configurated the applicationContenxt.xml in this way:

    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
            </list>
        </property>
    </bean>
    <bean id="contentNegotiatingViewResolver" 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.MappingJacksonJsonView"/>
            </list>
        </property>
    </bean>
    <bean class="com.MyController"></bean>
    And this is the code of my controller:

    Code:
    @Controller(value="MyController")
    public class MyController {
    @RequestMapping(value="/getValue", method=RequestMethod.GET)
        public ModelAndView getValue() {
        Map model = new HashMap();
        model.put("asasa", "bbbbb");
        model.put("cccc", "ddddd");
          return new ModelAndView("jsonView",model);
     }
    }
    I'm missing something about xml configuration or Java code? I have always error 404 while trying to invoke this resource: http://localhost:8080/fss/MyController/getValue

  2. #2
    Join Date
    Jun 2011
    Posts
    2

    Default

    Try to start debug your code from DispatcherServlet#doDispatch. Review all HandlerMapping(s), View Resolvers, etc DispatcherServlet operates with.

    Usually all such simple issues are simply can be resolved by debugging.

Posting Permissions

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