ErrorPageFilter<\/strong><\/div>\n
\nWhitelabel Error Page<\/p>\n
\u8fd9\u7c7b\u56fe\u76f8\u4fe1\u5927\u5bb6\u6ca1\u5c11\u89c1\uff0cSpring Boot \u53ea\u8981\u51fa\u9519\uff0c\u4f53\u73b0\u5728\u9875\u9762\u4e0a\u7684\u5c31\u662f\u8fd9\u4e2a\u3002\u5982\u679c\u4f60\u7528Postman\u4e4b\u7c7b\u7684\u6d4b\u8bd5\u51fa\u4e86\u5f02\u5e38\u5219\u662f\uff1a<\/p>\n
\r\n{ \r\n \"timestamp\": \"2021-04-29T22:45:33.231+0000\", \r\n \"status\": 500, \r\n \"message\": \"Internal Server Error\", \r\n \"path\": \"foo\/bar\" \r\n} \r\n<\/pre>\n\u8fd9\u4e2a\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u5462?Spring Boot\u5728\u542f\u52a8\u65f6\u4f1a\u6ce8\u518c\u4e00\u4e2aErrorPageFilter\uff0c\u5f53Servlet\u53d1\u751f\u5f02\u5e38\u65f6\uff0c\u8be5\u8fc7\u6ee4\u5668\u5c31\u4f1a\u62e6\u622a\u5904\u7406\uff0c\u5c06\u5f02\u5e38\u6839\u636e\u4e0d\u540c\u7684\u7b56\u7565\u8fdb\u884c\u5904\u7406\uff1a\u5f53\u5f02\u5e38\u5df2\u7ecf\u5728\u5904\u7406\u7684\u8bdd\u76f4\u63a5\u5904\u7406\uff0c\u5426\u5219\u8f6c\u53d1\u7ed9\u5bf9\u5e94\u7684\u9519\u8bef\u9875\u9762\u3002\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u53bb\u770b\u4e0b\u6e90\u7801\uff0c\u903b\u8f91\u4e0d\u590d\u6742\uff0c\u8fd9\u91cc\u5c31\u4e0d\u8d34\u4e86\u3002<\/p>\n
\u53e6\u5916\u5f53\u4e00\u4e2a Servlet \u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u65f6\uff0c\u5904\u7406\u5f02\u5e38\u7684Servlet\u53ef\u4ee5\u4eceHttpServletRequest\u91cc\u9762\u5f97\u5230\u51e0\u4e2a\u5c5e\u6027\uff0c\u5982\u4e0b\uff1a
\n
\n\u5f02\u5e38\u5c5e\u6027<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u4ece\u4e0a\u9762\u7684\u51e0\u4e2a\u5c5e\u6027\u4e2d\u83b7\u53d6\u5f02\u5e38\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n
\u9ed8\u8ba4\u9519\u8bef\u9875\u9762<\/strong><\/div>\n\u901a\u5e38Spring Boot\u51fa\u73b0\u5f02\u5e38\u9ed8\u8ba4\u4f1a\u8df3\u8f6c\u5230\/error\u8fdb\u884c\u5904\u7406\uff0c\u800c\/error\u7684\u76f8\u5173\u903b\u8f91\u5219\u662f\u7531BasicErrorController\u5b9e\u73b0\u7684\u3002<\/p>\n
\r\n@Controller \r\n@RequestMapping(\"${server.error.path:${error.path:\/error}}\") \r\npublic class BasicErrorController extends AbstractErrorController { \r\n \/\/\u8fd4\u56de\u9519\u8bef\u9875\u9762 \r\n @RequestMapping(produces = MediaType.TEXT_HTML_VALUE) \r\n public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) { \r\n HttpStatus status = getStatus(request); \r\n Map model = Collections \r\n .unmodifiableMap(getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.TEXT_HTML))); \r\n response.setStatus(status.value()); \r\n ModelAndView modelAndView = resolveErrorView(request, response, status, model); \r\n return (modelAndView != null) ? modelAndView : new ModelAndView(\"error\", model); \r\n } \r\n \/\/ \u8fd4\u56dejson \r\n @RequestMapping \r\n public ResponseEntity