我在for(i=0;i<=(l.length-1);i++)
中有以下@ExceptionHandler
方法:
@RestControllerAdvice
而 @ExceptionHandler(BusinessException.class)
public ResponseEntity<Object> onException(BusinessException exception, WebRequest request) {
Locale locale = request.getLocale();
String message = messageSource.getMessage(exception.errorCode.toString(),
exception.arguments, locale);
ErrorDto errorDto = new ErrorDto(
exception.errorCode,
exception.arguments,
message
);
return new ResponseEntity(errorDto, new HttpHeaders(), HttpStatus.CONFLICT);
}
是:
ErrorDto
但抛出public class ErrorDto {
ErrorCode errorCode;
String[] arguments = new String[]{};
String message;
public ErrorDto(ErrorCode errorCode, String[] arguments, String message){
this.errorCode = errorCode;
this.arguments = arguments;
this.message = message;
}
}
时得到的响应是:
BusinessException
为什么我在响应中看不到{
"timestamp": 1500459833663,
"status": 500,
"error": "Internal Server Error",
"exception": "com.ciet.app.exceptions.BusinessException",
"message": "No message available",
"path": "/CietApi/errorCodeTest"
}
?
答案 0 :(得分:1)
ErrorDto
字段需要公开或需要公开获取者。