【发布时间】:2018-05-20 00:56:52
【问题描述】:
我有带有以下签名的控制器方法:
@PostMapping("/rest_upload")
public DeferredResult<ResponseEntity> upload(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request) throws IOException {
我有以下异常处理程序:
@ExceptionHandler(MultipartException.class)
@ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
@ResponseBody
public String handleMaxUploadSizeExceededException(MultipartException e) {
logger.warn("MultipartException occurred", e);
String rootCauseMessage = ExceptionUtils.getRootCauseMessage(e);
return rootCauseMessage.substring(rootCauseMessage.indexOf(":") + 1);
}
当我发送大小(120MB)超过可配置最大值(100MB)的文件时,此处理程序会调用但在浏览器中我看到以下内容:
和细节:
我该如何解决这个问题?
【问题讨论】:
-
能否附上处理异常的控制器代码?
-
@Datta,你是什么意思?
-
附加控制器代码也可以处理异常
-
这段代码调用还不够吗?我发布了解决方案
标签: java spring spring-mvc tomcat exception-handling