@ControllerAdvice(annotations=org.springframework.web.bind.annotation.RestController.class) public class ResponseEntityExceptionHandler extends Object implements org.springframework.beans.factory.InitializingBean
ResponseEntityExceptionHandler
The difference is that all handlers use HttpServletRequest instead of
WebRequest because we want to
be able to use a LocaleResolver for
internationalization https://jira.spring.io/browse/SPR-8580ResponseEntityExceptionHandler| 限定符和类型 | 字段和说明 |
|---|---|
protected org.apache.commons.logging.Log |
logger |
static String |
PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.
|
protected static org.apache.commons.logging.Log |
PAGE_NOT_FOUND_LOGGER
Additional logger to use when no mapped handler is found for a request.
|
| 构造器和说明 |
|---|
ResponseEntityExceptionHandler() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet() |
protected ErrorContainer |
convert2ErrorContainer(Throwable throwable,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request) |
protected ErrorContainer |
convert2ErrorContainer(Throwable throwable,
ErrorCode errorCode,
Object[] messageArguments,
javax.servlet.http.HttpServletRequest request) |
protected String |
getErrorMessage(Throwable throwable,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request) |
protected String |
getErrorMessage(Throwable throwable,
ErrorCode errorCode,
Object[] messageArguments,
javax.servlet.http.HttpServletRequest request) |
protected org.springframework.web.servlet.LocaleResolver |
getLocaleResolver() |
protected org.springframework.context.MessageSource |
getResourceBundle() |
protected org.springframework.http.ResponseEntity<ErrorContainer> |
getResponseEntity(javax.servlet.http.HttpServletRequest request,
org.springframework.http.HttpHeaders httpHeaders,
Throwable throwable,
ErrorCode errorCode) |
protected org.springframework.http.ResponseEntity<ErrorContainer> |
getResponseEntity(javax.servlet.http.HttpServletRequest request,
org.springframework.http.HttpHeaders httpHeaders,
Throwable throwable,
ErrorCode errorCode,
Object[] messageArguments) |
protected org.springframework.http.ResponseEntity<Object> |
handleAccessDeniedException(org.springframework.security.access.AccessDeniedException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request) |
protected org.springframework.http.ResponseEntity<Object> |
handleApplicationException(ApplicationException exception,
org.springframework.http.HttpHeaders headers,
javax.servlet.http.HttpServletRequest request) |
protected org.springframework.http.ResponseEntity<Object> |
handleBindException(org.springframework.validation.BindException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for BindException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for ConversionNotSupportedException.
|
org.springframework.http.ResponseEntity<Object> |
handleException(Exception exception,
javax.servlet.http.HttpServletRequest request)
Provides handling for standard Spring MVC exceptions.
|
org.springframework.http.ResponseEntity<ErrorContainer> |
handleException(Throwable e,
javax.servlet.http.HttpServletRequest request) |
protected org.springframework.http.ResponseEntity<Object> |
handleExceptionInternal(Exception exception,
ErrorContainer body,
org.springframework.http.HttpHeaders headers,
org.springframework.http.HttpStatus status,
javax.servlet.http.HttpServletRequest request)
A single place to customize the response body of all Exception types.
|
protected org.springframework.http.ResponseEntity<Object> |
handleHttpMediaTypeNotAcceptable(org.springframework.web.HttpMediaTypeNotAcceptableException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for HttpMediaTypeNotAcceptableException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for HttpMediaTypeNotSupportedException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for HttpMessageNotReadableException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for HttpMessageNotWritableException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for HttpRequestMethodNotSupportedException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for MethodArgumentNotValidException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for MissingServletRequestParameterException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for MissingServletRequestPartException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleNoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for NoHandlerFoundException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for NoSuchRequestHandlingMethodException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for ServletRequestBindingException.
|
protected org.springframework.http.ResponseEntity<Object> |
handleTypeMismatch(org.springframework.beans.TypeMismatchException exception,
org.springframework.http.HttpHeaders headers,
ErrorCode errorCode,
javax.servlet.http.HttpServletRequest request)
Customize the response for TypeMismatchException.
|
boolean |
isDeveloperEnabled() |
boolean |
isI18nEnabled() |
void |
setDeveloperEnabled(boolean developerEnabled) |
void |
setI18nEnabled(boolean i18nEnabled) |
void |
setLocaleResolver(org.springframework.web.servlet.LocaleResolver localeResolver) |
void |
setResourceBundle(org.springframework.context.MessageSource resourceBundle) |
protected final org.apache.commons.logging.Log logger
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
PAGE_NOT_FOUND_LOGGER,
常量字段值protected static final org.apache.commons.logging.Log PAGE_NOT_FOUND_LOGGER
protected org.springframework.context.MessageSource getResourceBundle()
public void setResourceBundle(org.springframework.context.MessageSource resourceBundle)
protected org.springframework.web.servlet.LocaleResolver getLocaleResolver()
public void setLocaleResolver(org.springframework.web.servlet.LocaleResolver localeResolver)
public boolean isI18nEnabled()
public void setI18nEnabled(boolean i18nEnabled)
public boolean isDeveloperEnabled()
public void setDeveloperEnabled(boolean developerEnabled)
@ExceptionHandler(value={org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException.class,org.springframework.web.HttpRequestMethodNotSupportedException.class,org.springframework.web.HttpMediaTypeNotSupportedException.class,org.springframework.web.HttpMediaTypeNotAcceptableException.class,org.springframework.web.bind.MissingServletRequestParameterException.class,org.springframework.web.bind.ServletRequestBindingException.class,org.springframework.beans.ConversionNotSupportedException.class,org.springframework.beans.TypeMismatchException.class,org.springframework.http.converter.HttpMessageNotReadableException.class,org.springframework.http.converter.HttpMessageNotWritableException.class,org.springframework.web.multipart.support.MissingServletRequestPartException.class,org.springframework.web.bind.MethodArgumentNotValidException.class,org.springframework.validation.BindException.class,org.springframework.web.servlet.NoHandlerFoundException.class,org.springframework.security.access.AccessDeniedException.class,ApplicationException.class})
public final org.springframework.http.ResponseEntity<Object> handleException(Exception exception,
javax.servlet.http.HttpServletRequest request)
exception - the target exceptionrequest - the current request@ExceptionHandler(value=java.lang.Throwable.class) public org.springframework.http.ResponseEntity<ErrorContainer> handleException(Throwable e, javax.servlet.http.HttpServletRequest request)
protected org.springframework.http.ResponseEntity<Object> handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleHttpMediaTypeNotAcceptable(org.springframework.web.HttpMediaTypeNotAcceptableException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleTypeMismatch(org.springframework.beans.TypeMismatchException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleNoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
handleExceptionInternal(Exception, ErrorContainer, HttpHeaders, HttpStatus, HttpServletRequest)
.exception - the exceptionheaders - the headers to be written to the responseerrorCode - the selected response statusrequest - the current requestResponseEntity instanceprotected org.springframework.http.ResponseEntity<Object> handleAccessDeniedException(org.springframework.security.access.AccessDeniedException exception, org.springframework.http.HttpHeaders headers, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
exception - headers - errorCode - request - protected org.springframework.http.ResponseEntity<Object> handleApplicationException(ApplicationException exception, org.springframework.http.HttpHeaders headers, javax.servlet.http.HttpServletRequest request)
exception - headers - request - protected org.springframework.http.ResponseEntity<Object> handleExceptionInternal(Exception exception, ErrorContainer body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, javax.servlet.http.HttpServletRequest request)
null by default.exception - the exceptionbody - the body to use for the responseheaders - the headers to be written to the responsestatus - the selected response statusrequest - the current requestprotected org.springframework.http.ResponseEntity<ErrorContainer> getResponseEntity(javax.servlet.http.HttpServletRequest request, org.springframework.http.HttpHeaders httpHeaders, Throwable throwable, ErrorCode errorCode)
request - requesthttpHeaders - httpHeadersthrowable - throwableerrorCode - errorCodeprotected org.springframework.http.ResponseEntity<ErrorContainer> getResponseEntity(javax.servlet.http.HttpServletRequest request, org.springframework.http.HttpHeaders httpHeaders, Throwable throwable, ErrorCode errorCode, Object[] messageArguments)
request - requesthttpHeaders - httpHeadersthrowable - throwableerrorCode - errorCodemessageArguments - messageArgumentsprotected String getErrorMessage(Throwable throwable, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
throwable - throwableerrorCode - errorCoderequest - requestprotected String getErrorMessage(Throwable throwable, ErrorCode errorCode, Object[] messageArguments, javax.servlet.http.HttpServletRequest request)
throwable - throwableerrorCode - errorCodemessageArguments - messageArgumentsrequest - requestprotected ErrorContainer convert2ErrorContainer(Throwable throwable, ErrorCode errorCode, javax.servlet.http.HttpServletRequest request)
throwable - the target exceptionerrorCode - errorCoderequest - requestprotected ErrorContainer convert2ErrorContainer(Throwable throwable, ErrorCode errorCode, Object[] messageArguments, javax.servlet.http.HttpServletRequest request)
throwable - throwableerrorCode - errorCodemessageArguments - messageArgumentsrequest - requestCopyright © 2015. All rights reserved.