2023年12月18日发(作者:)
import tions;import ;import ;import rvletRequest;import rvletResponse;import roperties;import eStacktrace;import ttributes;import ctServletWebServerFactory;import atus;import ype;import seEntity;import ller;import ;import tMapping;import ndView;/** * Basic global error {@link Controller @Controller}, rendering {@link ErrorAttributes}. * More specific errors can be handled either using Spring MVC abstractions (e.g. * {@code @ExceptionHandler}) or by adding servlet * {@link AbstractServletWebServerFactory#setErrorPages server error pages}. * * @author Dave Syer * @author Phillip Webb * @author Michael Stummvoll * @author Stephane Nicoll * @since 1.0.0 * @see ErrorAttributes * @see ErrorProperties */@Controller//如果没有配置就去找,如果没有配置默认路径为/error@RequestMapping("${:${:/error}}")public class BasicErrorController extends AbstractErrorController { private final ErrorProperties errorProperties; /** * Create a new {@link BasicErrorController} instance. * @param errorAttributes the error attributes * @param errorProperties configuration properties */ public BasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) { this(errorAttributes, errorProperties, ist()); } /** * Create a new {@link BasicErrorController} instance. * @param errorAttributes the error attributes * @param errorProperties configuration properties * @param errorViewResolvers error view resolvers */ public BasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties, List
/* * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * /licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package ;import riter;import Writer;import ;import HashMap;import ;import tException;import rvletRequest;import rvletResponse;import d;import ;import atus;import Utils;import gResult;import Error;import ArgumentNotValidException;import tAttributes;import uest;import rExceptionResolver;import ndView;/** * Default implementation of {@link ErrorAttributes}. Provides the following attributes * when possible: *
- *
- timestamp - The time that the errors were extracted *
- status - The status code *
- error - The error reason *
- exception - The class name of the root exception (if configured) *
- message - The exception message *
- errors - Any {@link ObjectError}s from a {@link BindingResult} exception *
- trace - The exception stack trace *
- path - The URL path when the exception was raised *
boolean includeStackTrace) { Throwable error = getError(webRequest); if (error != null) { while (error instanceof ServletException && se() != null) { error = se(); } if (eException) { ("exception", ss().getName()); } addErrorMessage(errorAttributes, error); if (includeStackTrace) { addStackTrace(errorAttributes, error); } } Object message = getAttribute(webRequest, "e"); if ((!y(message) || ("message") == null) && !(error instanceof BindingResult)) { ("message", y(message) ? "No message available" : message); } } private void addErrorMessage(Map


发布评论