tôi đã thiết lập kích thước tập tin tối đa đểtập tin dung nhiều kích thước tối đa ngoại lệ - khởi động mùa xuân embbeded tomcat
multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb
Đây là bộ điều khiển của tôi:
@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));
}
đây là thông báo lỗi
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)
Và kết quả cuối cùng sau khi yêu cầu với tập tin quá khổ là vấn đề tải trang. Tôi không nhận được bất kỳ lỗi nào khác trong stack trace vì vậy tôi kinda mắc kẹt với những gì đang thực sự xảy ra. Oh yeah tôi đã thử nhiều giải pháp khác như đăng ký bộ lọc, xử lý ngoại lệ trong ErrorController. Mỗi lần tôi sẽ kết thúc với cùng một kết quả - sự cố máy chủ.
EDIT 2
My ngoại lệ xử lý lớp:
@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);
}
}
Bạn chưa hiển thị đủ mã của mình. Ví dụ, 'handleExceptionInternal' làm gì. [Ví dụ tối thiểu, đầy đủ, có thể xác minh] (http://stackoverflow.com/help/mcve) sẽ giúp mọi người dễ dàng trợ giúp bạn hơn. –
'handleExceptionInternal' là phương thức nội bộ của 'ResponseEntityExceptionHandler', theo tài liệu" Một lớp cơ sở thuận tiện cho các lớp {@link ControllerAdvice @ControllerAdvice} * muốn cung cấp xử lý ngoại lệ tập trung ". –