[排错] 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

问题圆满解决

原文地址:https://www.cnblogs.com/unityworld/p/11857485.html