我已經設置最大文件大小多部分文件的最大尺寸異常 - 春季啓動embbeded tomcat的
multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb
這是我的控制器:
@RequestMapping(method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@Secured(Privileges.CAN_USER_READ)
public void create(@RequestParam("file")final MultipartFile file,Principal principal) throws IllegalStateException, IOException,MultipartException{
medicalHistoryService.create(new MedicalHistory(file));
}
這是錯誤信息
2016-03-03 13:48:24.560 WARN 4992 --- [nio-8080-exec-1] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
2016-03-03 13:48:25.545 WARN 4992 --- [nio-8080-exec-2] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
超大文件請求後的最終結果是問題加載頁面。我沒有得到任何其他錯誤的堆棧跟蹤,所以我有點卡住了實際發生的事情。噢,我已經嘗試了許多其他解決方案,例如註冊過濾器,在ErrorController中處理異常。每次我都會得到相同的結果 - 服務器崩潰。
EDIT 2
我的異常處理類:
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends
ResponseEntityExceptionHandler{
// 413 MultipartException - file size too big
@ExceptionHandler({MultipartException.class,FileSizeLimitExceededException.class,java.lang.IllegalStateException.class})
public ResponseEntity<Object> handleSizeExceededException(final WebRequest request, final MultipartException ex) {
//log.warn("413 Status Code. File size too large {}", ex.getMessage());
log.warn(ex.getMessage());
final ApiError apiError = message(HttpStatus.PAYLOAD_TOO_LARGE, ex);
return handleExceptionInternal(ex, apiError, new HttpHeaders(), HttpStatus.PAYLOAD_TOO_LARGE, request);
}
}
您未顯示足夠的代碼。例如,'handleExceptionInternal'是做什麼的。一個[最小的,完整的,可驗證的例子](http://stackoverflow.com/help/mcve)將使人們更容易幫助你。 –
'handleExceptionInternal'是'ResponseEntityExceptionHandler'的內部方法,它是通過「希望提供集中式異常處理的{Controller LinkAdvice @ControllerAdvice}類 *的便利基類」。 –