spring mvc 返回httpstate 406

spring 版本:3.2.4 html

跟踪到spring mvc中查看到的异常:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation java

spring中抛出异常的方法: web

org.springframework.web.servlet.DispatcherServlet.doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception spring

错误的方法代码:

@RequestMapping(value="awardByPage",produces="text/plain;charset=UTF-8")
public @ResponseBody JSONResponse awardByPage(@RequestParam int pageIndex) {
   return JSONResponse.buildSuccess(awardService.awardLogByPage(pageIndex));
}

解决方案:

1. 删除代码中的: json

,produces="text/plain;charset=UTF-8"
2. 网络上查找的其它解决方案:

    

<!-- 启动JSON格式的配置 -->
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">	
<!--解决 HttpMediaTypeNotAcceptableException: Could not find acceptable representation -->
      <property name="supportedMediaTypes">
           <list>
               <value>text/html;charset=UTF-8</value>
           </list>
       </property>
</bean>

产生此问题的其它缘由及解决方法:

1. controller中返回的内容没有get方法, 网络

解决办法:添加get方法; mvc

2. 因为设置了@ResponseBody,要把对象转换成json格式,缺乏转换依赖的jar包,故此错。 
解决办法:    加入依赖的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar问题解决。
app

相关文章
相关标签/搜索