springmvc @ResponseBody HttpMediaTypeNotAcceptableException
2017-04-28 00:00
2695 查看
摘要: [ERROR]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
[ERROR]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
解决方法:
注意:1,试过在xml中配置也不能解决.
[ERROR]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
解决方法:
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); /** * 清除数据 */ @RequestMapping(value = "/reset") @ResponseBody public void reset(HttpServletResponse response) throws Exception{ response.setContentType("application/json; charset=UTF-8"); /*业务逻辑*/ //将对象转为json字符串输出到body中 response.getWriter().print(OBJECT_MAPPER.writeValueAsString(new Response().success("清除数据成功"))); }
注意:1,试过在xml中配置也不能解决.
<!-- 启动JSON格式的配置 --> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <!-- 解决 HttpMediaTypeNotAcceptableException: Could not find acceptable representation --> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean>
2,将@RequestMapping(value = "/reset")改为@RequestMapping(value = "/reset",produces = MediaType.APPLICATION_JSON_VALU)也不行.
相关文章推荐
- spring 4 异常HttpMediaTypeNotAcceptableException解决方案
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio
- 关于Spring3 MVC的 HttpMediaTypeNotSupportedException
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio
- 关于Spring3 MVC的 HttpMediaTypeNotSupportedException
- spring boot HttpMediaTypeNotSupportedException
- HTTP Status 415 Unsupported Media Type [Spring MVC @RequestBody传递Json数据 ]
- ajax使用向Spring MVC发送JSON数据出现 org.springframework.web.HttpMediaTypeNotSupportedException: Content type
- 在Spring Cloud框架整合微服务时出现的org.springframework.web.HttpMediaTypeNotSupportedException异常问题
- Spring Boot: HttpMediaTypeNotAcceptableException: Could not find acceptable representation原因及解决方法
- org.springframework.web.HttpMediaTypeNotSupportedException: Unsupported Media Type, status=415
- HttpMediaTypeNotAcceptableException: Could not find acceptable representation原因及解决方法
- org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing
- org.springframework.web.HttpMediaTypeNotAccepta... 3ff8
- nested exception is java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()
- SpringMVC @RequestBody接受post json对象 (415 Unsupported media type)
- How to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?