【发布时间】:2019-03-14 03:41:09
【问题描述】:
我有一个使用 Spring Boot 的 Spring REST 项目。我已经将 jackson-dataformat-xml 声明为 maven 中的依赖项,以在接受标头为 application/xml(并且它本机接受 application/json)时支持 xml。
我遇到的问题是,当我将接受标头设置为这两个以外的任何内容时(例如 application/dsfas 或 text/html,我收到服务器错误并出现以下异常:
23:36:04.368 [http-nio-8082-exec-5] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Failure in @ExceptionHandler protected org.springframework.http.ResponseEntity<java.lang.Object> com.mergg.common.web.RestResponseEntityExceptionHandler.handleNotFound(java.lang.RuntimeException,org.springframework.web.context.request.WebRequest)
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
关于如何修复的任何想法,以便我可以忽略接受标头并返回 json 或告诉客户端这是一个错误的请求?
【问题讨论】:
标签: spring content-negotiation