[排错] SpringBoot 警告 Could not find acceptable representation
环境
Java 1.8
SpringBoot 2.1.9
Java 接口代码
@ResponseBody
@RequestMapping(value = "cloud", method = RequestMethod.GET,produces = "applications/json;charset=UTF-8")
public Boolean queryItemInfoAllInCloud(){
ItemInfo itemInfo = itemService.queryItemInfoAllInCloud();
if(itemInfo == null) return false;
return true;
}
请求路径
http://127.0.0.1:8080/controller/cloud/
警告信息
2019-11-14 14:56:57.465 WARN 57604 Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
这句话翻译过来就是 "找不到可接受的表示" 可以理解为浏览器找不到合适的类型来显示请求接口的返回值?
然后问题是出在
produces = "applications/json;charset=UTF-8"
这段代码的意思是返回 json 类型的响应数据, 但是我们接口的返回值是 Boolean 类型的, 当然无法返回
所以要这段代码改成
produces=MediaType.APPLICATION_JSON_VALUE
问题圆满解决
[排错] SpringBoot 警告 Could not find acceptable representation的更多相关文章
- Springboot实体类转JSON报错Could not find acceptable representation & 设置访问项目根路径的默认欢迎页面
=================实体类转JSON报错的解决办法============= 之前在springmvc的时候也报过这个错,原因以及springmvc中解决办法参考:https://www ...
- SpringBoot导出excel数据报错Could not find acceptable representation
转自:https://blog.csdn.net/mate_ge/article/details/93518286?utm_source=distribute.pc_relevant.none-tas ...
- 76. Spring Boot完美解决(406)Could not find acceptable representation原因及解决方法
[原创文章] 使用Spring Boot的Web项目,处理/login请求的控制器方法(该方法会返回JSON格式的数据).此时如果访问localhost:8080/login.html, ...
- spring使用jackson返回object报错:Handler execution resulted in exception: Could not find acceptable representation
问题:在springmvc中添加Jackson jar包返回Object类型,处理器方法的produces属性不写,默认根据类型,但如果指定了(错误原因)produces = "text/h ...
- 使用@ResponseBody 出现错误Could not find acceptable representation
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio ...
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
异常信息 org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable represen ...
- 关于"Could not find acceptable representation"错误
在项目中调用一个第三方服务,第三方服务是用Spring Boot写成的.结果调用时返回"Could not find acceptable representation"错误. 经 ...
- springboot中的406(Not Acceptable)错误
今天遇到一个很奇怪的问题,我用springboot开发时,用ajax请求服务想返回json数据,页面总是报406错误,这个错误使我郁闷了很久,原来我的后台服务是这么写的 看到没value的后面有个.h ...
- Could not find acceptable representation
引起的原因: 由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,故此错. 解决办法: <dependency> <groupId> ...
随机推荐
- SpringMVC开发RESTful接口
概念: 什么是REST? REST是Representational State Transfer的缩写.翻译为"表现层状态转化",restful是一种接口设计风格,它不是一个协议 ...
- 【代码审计】seacms 前台Getshell分析
一.漏洞分析 漏洞触发点search.php 211-213行 跟进parseIf 函数 ./include/main.class.php 这里要注意 3118行的位置,可以看到未做任何处理的eval ...
- 【应急响应】Linux安全加固
一.补丁管理 1.查看系统信息 uname -a 2.配置yun源 CentosOS 可以直接升级 RHEL系列可以配置使用CentosOS源 3.升级软件包 yum –y update 二.安全工具 ...
- 解决ubuntu和win10双系统时间不一致
1.在ubuntu下安装ntpdate sudo apt install ntpdate 2.设置同步windows时间 sudo ntpdate time.windows.com 3.把时间更新到硬 ...
- 解决laravel出现Syntax error or access violation: 1055 '***' isn't in GROUP BY
laravel 5.3 以后默认开启 mysql严格模式(strict)在mysql在严格模式下, 并且开启了ONLY_FULL_GROUP_BY的情况下,group by 的字段没有出现在 sele ...
- java 数据类型优先级
由低到高:byte,short,char—> int —> long—> float —> double 1. 不能对boolean类型进行类型转换. 2. 不能把对象类型转换 ...
- VS2017编译错误:#error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version
VS2017编译错误:#error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll ve ...
- 刷题5. Longest Palindromic Substring
一.题目说明 Longest Palindromic Substring,求字符串中的最长的回文. Difficuty是Medium 二.我的实现 经过前面4个题目,我对边界考虑越来越"完善 ...
- DIV 设置垂直居中
要说面试官经常问的问题中“如何将一个块元素水平垂直居中”就算一个. 之前的面试中也有中招,现在总结一下. 1.CSS垂直水平居中 要让DIV水平和垂直居中,必需知道该DIV得宽度和高度,然后设置位置为 ...
- Java的Path、Paths和Files
前言 因为这几天被java.nio的这几个接口和工具类卡到了,就顺便地查了一波文档以及使用方法,这篇其实更像是API的复制粘贴,只不过我在注释里多写了一些output和注意事项,看不惯API的可以选择 ...