文章目录
tomcat默认设置1MB
最近收到前端反馈,小程序中用户上传图片出错,赶紧瞅下后台日志,哦吼,真出错了。提示tomcat上传文件最大限制为1MB,根据前端大佬的要求,需要将最大限制改为5MB。
Maximum upload size exceeded; nested exception is java.lang.IllegalStateException:
org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException:
the request was rejected because its size (39994658) exceeds the configured maximum (10485760)
解决方案
目前网上有两种解决方案:
spring.http.multipart配置(无效,受springboot版本限制)
在application.yml中配置如下:
spring:
http:
multipart:
maxFileSize: 5MB
maxRequestSize: 10MB
经过测试,上述方法无效!!因为springboot2.X后不支持该设置!!!
spring.servlet.multipart配置
在application.yml中配置如下:
spring:
servlet:
multipart:
maxFileSize: 5MB
maxRequestSize: 10MB
亲测有效哦~
遇到的问题
配置后程序无法启动(5MB需要大写)
报错如下:
Failed to bind properties under ‘spring.servlet.multipart.max-file-size’ to org.springframework.util.unit.DataSize
解决方案:将5Mb修改为5MB