【发布时间】:2020-08-16 19:42:24
【问题描述】:
我的休息控制器包含以下后期映射:
@PostMapping
public ResponseEntity<RespDTO> uploadDocument(@ModelAttribute @Valid RequestDTO requestDTO,@RequestParam(value = "fileContent") MultipartFile fileContent) throws ServiceException, URISyntaxException { }
ServiceExceptionn 是特定于我的应用程序的自定义异常。
控制器建议如下所示:
@ControllerAdvice
public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait {
@Override
public ResponseEntity process(@Nullable ResponseEntity<Problem> entity, NativeWebRequest request) {
}
@ExceptionHandler(FileTooLargeException.class)
public ResponseEntity<ResponseDTO> handleFileTooLargeException(FileTooLargeException ex, @Nonnull NativeWebRequest request){
}
}
application.yml 包含以下属性:
spring:
servlet:
multipart:
max-file-size: 2MB
如果我使用大小大于 2MB 的文件调用其余 api,那么我会遇到以下异常:
io.undertow.server.handlers.form.MultiPartParserDefinition$FileTooLargeException: UT000054: The maximum size 5242880 for an individual file in a multipart request was exceeded
我在这里面临的问题是: 控制器建议未按预期工作。 handleFileTooLargeException - 这个方法必须被执行,因为它被注释了 ExceptionHandler 提到的特定异常类型。 但取而代之的是,控制进入控制器通知的处理方法。
无法理解我在这里缺少什么。
【问题讨论】:
-
这能回答你的问题吗? How to set the max size of upload file
标签: spring-boot controller-advice