使用Jackson的Spring REST

编程入门 行业动态 更新时间:2024-10-10 03:33:17
本文介绍了使用Jackson的Spring REST-400错误的请求记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经使用Jackson/JSON设置了春季REST,并且一切正常.

I have spring REST set up fine using Jackson/JSON and everything works.

但是我故意在消息的结构中引入了一个错误,该错误导致了400-错误的请求.但是服务器上没有日志输出.我所期望的错误将是杰克逊未知属性异常"之类的东西,但它被捕获,并且向客户端发送了400错误,但服务器上没有该异常的日志.

But I knowingly introduced an error in the structure of the message which resulted in a 400 - Bad Request. But there was no log output on the server. The error I would be expecting would be something like "Jackson unknown property exception" or whatever but it was caught and a 400 error was sent to the client, but no log of the exception on the server.

我不想明确调试服务器上的所有内容,但我希望像这样的Spring网络级异常明确标记为错误.

I don't want to debug everything on the server clearly, but I want Spring network level exceptions like this clearly labelled as error.

打开此功能的正确方法是什么?

What is the correct way to switch this on?

谢谢!

推荐答案

@ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public void handle(HttpMessageNotReadableException e) { logger.warn("Returning HTTP 400 Bad Request", e); }

更多推荐

使用Jackson的Spring REST

本文发布于:2023-10-10 17:54:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Jackson   Spring   REST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!