org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation


異常

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

原因之一(自我感覺)

設定的response的contentType同實際controller層返回的對象類型不一致。

@ResponseBody
@GetMapping(value = "xxx", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public Boolean test(){
    return true;
}
注意點
  • @ResponseBody 需存在,才可復現。(可以在Controller Class上,如果不存在,會直接走視圖解析器)
  • produces定義了 contentTypeapplication/octet-stream,實際返回了true
produces 用於指定response的類型和編碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM