Spring Boot 批量上传 FileCountLimitExceededException 文件数量超出异常
Spring Boot Tomcat About 2,110 words异常日志
org.apache.tomcat.util.http.fileupload.impl.FileCountLimitExceededException: attachment
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:459)
at org.apache.catalina.connector.Request.parseParts(Request.java:2576)
at org.apache.catalina.connector.Request.getParts(Request.java:2439)
at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:540)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:95)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88)
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:112)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1102)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:947)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:866)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1003)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:903)
解决方法
在Spring Boot的application.yaml中配置server.tomcat.max-part-count,默认:10个文件。
server:
tomcat:
max-part-count: 10
ControllerAdvice
可以全局捕获FileCountLimitExceededException,提示用户超出最大限制。
@Slf4j
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ApiExceptionResponseAdvice {
@ExceptionHandler
@ResponseStatus(HttpStatus.OK)
public Response onFileCountLimitExceededException(FileCountLimitExceededException e, HttpServletRequest request) {
String msg = e.getMessage() + ", max count: " + e.getLimit();
log.error("[advice][FileCountLimitExceededException] {}:{}, {}", request.getMethod(), request.getRequestURI(), msg);
return Response.fail("File Count Limit Exceeded");
}
}
Views: 8 · Posted: 2026-01-30
———         Thanks for Reading         ———
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...