Spring Mvc错误:此请求标识的资源只能生成具有不可接受特征的响应

时间:2014-06-10 13:23:26

标签: json rest spring-mvc jackson

控制器方法如下:

@RequestMapping(value="/login/vignesh1",method = RequestMethod.GET)
 @ResponseBody
  public String[] getAllOrders() {
  ArrayList<UserTest> orders = new ArrayList<UserTest>();
  UserTest userTest=new UserTest(); 
  userTest.setUsername("om Vigneshwarya namaha");
  orders.add(userTest);
  String [] s={"xuxk","gfhg"};
 return s ;
 }



Added the following configuration in the spring-servlet.xml 

<bean    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="mediaTypes">
 <map>
 <entry key="xml" value="application/xml" />
 <entry key="json" value="application/json" />
</map>
</property>
<property name="defaultViews">
 <list>
  <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
  <property name="marshaller">
  <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
   <property name="autodetectAnnotations" value="true"/>
  </bean>
  </property>
  </bean>
  <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
 </list>
 </property>
</bean>
 <!-- Configure to plugin JSON as request and response in method handler -->
  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonMessageConverter"/>
        </list>
    </property>
  </bean>

  <!-- Configure bean to convert JSON to POJO and vice versa -->
  <bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>


Added the follwoing jars :

杰克逊核-ASL-1.9.13.jar    杰克逊 - 数据绑定 - 2.2.3.jar   杰克逊映射器-ASL-1.9.13.jar   jackson.jar    XStream的-1.4.7.jar   xpp3-1.1.3.3.jar

现在我收到以下错误

HTTP状态406 - 此请求标识的资源只能生成具有根据请求不可接受的特征的响应&#34;接受&#34;头。

请帮帮我。

提前致谢

0 个答案:

没有答案