上传文件出现 aximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.

简介: 上传文件出现 aximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.

ERROR o.l.l.c.c.GlobalExceptionHandler - Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
   at
org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:121)

   at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:114)

   at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:87)

   at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:87)

   at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1176)

   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1011)

   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)

   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)

   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)

   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at com.github.xiaoymin.swaggerbootstrapui.filter.SecurityBasicAuthFilter.doFilter(SecurityBasicAuthFilter.java:84)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at com.github.xiaoymin.swaggerbootstrapui.filter.ProductionSecurityFilter.doFilter(ProductionSecurityFilter.java:53)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)

   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)

   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)

   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)

   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)

   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)

   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)

   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)

   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)

   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836)

   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747)

   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

   at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

   at org.apache.catalina.connector.Request.parseParts(Request.java:2899)

   at org.apache.catalina.connector.Request.parseParameters(Request.java:3194)

   at org.apache.catalina.connector.Request.getParameter(Request.java:1116)

   at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)

   at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:84)

   ... 23 common frames omitted

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

   at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633)

   at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)

   at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)

   at java.io.FilterInputStream.read(FilterInputStream.java:107)

   at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98)

   at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68)

   at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293)

   at org.apache.catalina.connector.Request.parseParts(Request.java:2855)

   ... 27 common frames omitted

 

 

文档说明表示,每个文件的配置最大为1Mb,单次请求的文件的总数不能大于10Mb。要更改这个默认值需要在配置文件(如application.properties)中加入两个配置

 

  1. multipart.maxFileSize = 10Mb
  2. multipart.maxRequestSize=100Mb

multipart.maxFileSize=10Mb是设置单个文件的大小, multipart.maxRequestSize=100Mb是设置单次请求的文件的总大小

如果是想要不限制文件上传的大小,那么就把两个值都设置为-1就行啦

*****************************后续更新******************************如果有误,请查看文末提示官方文档哈

Spring Boot1.4版本后配置更改为:

 

  1. spring.http.multipart.maxFileSize = 10Mb
  2. spring.http.multipart.maxRequestSize=100Mb

Spring Boot2.0之后的版本配置修改为:

 

  1. spring.servlet.multipart.max-file-size = 10MB
  2. spring.servlet.multipart.max-request-size=100MB

详情参考Spring Boot官方文档,感谢评论的小伙伴给出的建议更新提示。

**************

重要:根据评论区的老铁们给的提示,如果以上的配置有误,尝试将=更改为:或者将Mb单位更改为MB,大家以Spring Boot的官方文档为准哈,如果博文给大家带来麻烦,还请谅解,因为Spring Boot版本迭代很快,我已经很久没有接触了哈,谢谢大家,谢谢评论区的小伙伴。

相关文章
|
4天前
|
分布式计算 DataWorks Java
DataWorks操作报错合集之使用ODPS Tunnel Upload功能时,遇到报错:Java 堆内存不足,该如何解决
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
|
20天前
|
消息中间件 存储 Java
深度探索:使用Apache Kafka构建高效Java消息队列处理系统
【6月更文挑战第30天】Apache Kafka是分布式消息系统,用于高吞吐量的发布订阅。在Java中,开发者使用Kafka的客户端库创建生产者和消费者。生产者发送序列化消息到主题,消费者通过订阅和跟踪偏移量消费消息。Kafka以持久化、容灾和顺序写入优化I/O。Java示例代码展示了如何创建并发送/接收消息。通过分区、消费者组和压缩等策略,Kafka在高并发场景下可被优化。
79 1
|
1月前
|
Java 应用服务中间件 Apache
安装和配置Apache Tomcat是部署Java Web应用程序的常见任务
安装和配置Apache Tomcat是部署Java Web应用程序的常见任务
55 7
|
8天前
|
easyexcel Java Apache
EasyExcel导入的时候报错Caused by: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/File
EasyExcel导入的时候报错Caused by: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/File
|
8天前
|
Java
idea启动java服务报错OutOfMemoryError: GC overhead limit exceeded解决方法
idea启动java服务报错OutOfMemoryError: GC overhead limit exceeded解决方法
|
1月前
Exception in thread "main" java.lang.IllegalArgumentException: U+6570 ('.notdef') is not available in the font Helvetica-Bold, encoding: WinAnsiEncoding 这个问题如何解决
【6月更文挑战第19天】Exception in thread "main" java.lang.IllegalArgumentException: U+6570 ('.notdef') is not available in the font Helvetica-Bold, encoding: WinAnsiEncoding 这个问题如何解决
78 2
|
1月前
|
监控 Java 数据库连接
Java一分钟之-JDBC连接池:HikariCP, Apache DBCP, C3P0
【6月更文挑战第14天】本文介绍了Java中常用的三种JDBC连接池——HikariCP、Apache DBCP和C3P0。HikariCP以其高性能和低延迟领先,适合高并发环境;Apache DBCP稳定易配置;C3P0则提供高度可定制选项。文章讨论了各连接池的常见问题及避免策略,如配置不当、连接泄露等,并给出示例代码以供参考。选择合适的连接池并正确配置能有效提升应用性能。
43 7
|
12天前
|
监控 Java
【Java】已解决:Java.lang.OutOfMemoryError: GC overhead limit exceeded
【Java】已解决:Java.lang.OutOfMemoryError: GC overhead limit exceeded
5 0
|
16天前
|
Java 数据库连接 mybatis
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
|
19天前
|
Java 应用服务中间件 API
如何安装与使用Java EE 8、Servlet 3.0及Apache Maven进行高效开发
【7月更文第1天】搭建高效Java EE 8开发环境,包括安装JDK、选择WildFly或Payara Server作为应用服务器,以及安装Apache Maven。使用Maven创建Servlet 3.0 Web项目,编写 HelloWorldServlet,打包部署到服务器,通过访问特定URL测试应用。这一流程助力开发者实现快速原型和大型项目开发。
56 0

推荐镜像

更多