【滴滴】SpringBoot配置maxHttpPostSize参数

【滴滴】SpringBoot配置maxHttpPostSize参数

**SpringBoot配置maxHttpPostSize参数**

问题描述

问题描述

业务上有一个报表导出功能,导出当前页面查询出来的数据,导出时需要把数据传到后台进行导出,当数据量大于1000条时,后台导出就会出现报错,The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector。

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector

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

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

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

也就是说post请求参数超过了springboot的默认值2mb,需要去修改springboot配置的默认值。

通过各种搜索得到了统一的结果,修改如下所示:

#请求参数长度

server.tomcat.max-http-post-size=-1

#form表单长度

server.tomcat.max-http-form-post-size=-1

# 上传文件的大小限定

#spring.http.multipart.max-file-size=1024MB

#上传请求数据的大小限定,限定请求的总数据大小

#spring.http.multipart.max-request-size=1024MB

其中-1表示不限定大小,也可以配置成0或者具体数值。如果排查后如果没有效果的话,不妨试一下我的解决方案:

#post请求最大长度 springboot版本 1.4.3.RELEASE

server.maxHttpPostSize=209715200

org.springframework.boot.autoconfigure.web.ServerProperties配置类中

风雨相关