[排错] 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> ...
随机推荐
- SpringCloud Netflix Eureka
Eureka是Netflix开源的服务发现组件,基于REST,SpringCloud将它集成在子项目Spring Cloud Netflix中,从而实现服务的注册.发现. Eureka包含Server ...
- jquery动画系统
1.隐藏显示的方法: $(selector).show(speed,callback); $(selector).hide(1000); $(selector).toggle("slow&q ...
- vue axios使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 多核 CPU 和多个 CPU 有何区别?
原文来自:http://www.solves.com.cn/it/yj/CPU/2019-06-24/1122.html 多核CPU和多CPU的区别主要在于性能和成本.多核CPU性能最好,但成本最高: ...
- jmeter实现一次登录,多次业务请求(不同线程组间共享cookie和变量)
实现目的 很多时候,在进行性能测试时,需要先登录,然后再对需求的事务进行相关性能测试,此时的登录操作,并不在本次性能测试的范围内,所以我们只需要登录一次,然后获取登录成功后的cookie等,并将coo ...
- java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/com.alibaba.druid.filter.Filter].
九月 11, 2019 2:56:36 下午 org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading ...
- Validation failed for one or more entities. See ‘EntityValidationErrors
try{ context.SaveChanges(); } catch (DbEntityValidationException ex) { var errorMessages = ex.Entity ...
- List 线性表:ArrayLis,LinkedList
package seday11.list; import java.util.ArrayList;import java.util.List; /*** @author xingsir * java. ...
- 【PAT甲级】1088 Rational Arithmetic (20 分)
题意: 输入两个分数(分子分母各为一个整数中间用'/'分隔),输出它们的四则运算表达式.小数需要用"("和")"括起来,分母为0的话输出"Inf&qu ...
- SpringCloud全家桶学习之客户端负载均衡及自定义负载均衡算法----Ribbon(三)
一.Ribbon是什么? Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端 负载均衡的工具(这里区别于nginx的负载均衡).简单来说,Ribbon是Netf ...