上传文件出现 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版本迭代很快,我已经很久没有接触了哈,谢谢大家,谢谢评论区的小伙伴。

相关文章
|
18天前
|
Java 网络安全 Maven
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.sslSocketFactory(Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/X509TrustManager;)Lokhttp3/OkHttpClient$Builder; 问题处理
【10月更文挑战第26天】Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.sslSocketFactory(Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/X509TrustManager;)Lokhttp3/OkHttpClient$Builder; 问题处理
35 2
|
1月前
|
Java
让星星⭐月亮告诉你,Java异常分类[Throwable(Error/Exception(RuntimeException/其他异常)) 检查时异常 非检查时异常]
本文深入解析了Java异常处理机制,重点介绍了`Throwable`类及其子类`Error`和`Exception`,并通过实例代码、流程图和表格详细解释了异常的分类、区别及处理方法,帮助读者掌握异常处理的关键技巧,提升程序的稳定性和健壮性。
47 1
|
3月前
|
Java 测试技术 Maven
成功解决:nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
这篇文章介绍了解决Spring框架中出现的`java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource`错误的步骤,指出错误原因是缺少`spring-aop`模块的jar包,并提供了通过Maven依赖或手动添加jar包到项目中的方法来解决这个问题。
成功解决:nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
|
3月前
|
消息中间件 Java Kafka
【Azure 事件中心】在微软云中国区 (Mooncake) 上实验以Apache Kafka协议方式发送/接受Event Hubs消息 (Java版)
【Azure 事件中心】在微软云中国区 (Mooncake) 上实验以Apache Kafka协议方式发送/接受Event Hubs消息 (Java版)
|
4月前
|
消息中间件 Java Kafka
zookeeper:Unexpected exception, exiting abnormally ::java.io.EOFException
zookeeper:Unexpected exception, exiting abnormally ::java.io.EOFException
129 1
zookeeper:Unexpected exception, exiting abnormally ::java.io.EOFException
|
3月前
|
Java
Java使用FileInputStream&&FileOutputStream模拟客户端向服务器端上传文件(单线程)
Java使用FileInputStream&&FileOutputStream模拟客户端向服务器端上传文件(单线程)
83 1
|
3月前
|
Java 开发工具 Spring
【Azure Spring Cloud】使用azure-spring-boot-starter-storage来上传文件报错: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known
【Azure Spring Cloud】使用azure-spring-boot-starter-storage来上传文件报错: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known
|
3月前
|
Java
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
20 0
|
4月前
|
分布式计算 DataWorks Java
DataWorks操作报错合集之使用ODPS Tunnel Upload功能时,遇到报错:Java 堆内存不足,该如何解决
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
|
4月前
|
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
354 0

推荐镜像

更多