Springboot 异常返回值统一处理

Spring boot 处理 error 的基本流程:

 

Controller -> 发生错误 -> BasicErrorController -> 根据 @RequestMapping(produces) 判断调用 errorHtml 或者 error 方法

 

然后:

 

errorHtml -> getErrorAttributes -> ErrorViewResolver -> 错误显示页面

 

error -> getErrorAttributes -> @ResponseBody (直接返回JSON)。

 

 

当Zuul出现异常时,统一处理返回值,替换Springboot默认返回值。

 

 


©版权声明:本文为【翰林小院】(huhanlin.com)原创文章,转载时请注明出处!

发表评论

电子邮件地址不会被公开。