SpringBoot提交form表单 size大小
程序员文章站
2022-04-30 13:59:16
...
报错误信息
The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector.
可以看到在SB源码中post链接请求源码 默认参数
form表单pots提交size大小 超出默认限制
解决办法
更改tomcat的post限制大小
硬编码方式
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 设置post 参数大小
*
* @author tizzy
*/
@Configuration
public class HttpMaxPostSizeConfiguration {
// Set maxPostSize of embedded tomcat server to 10 megabytes (default is 2 MB, not large enough to support file uploads > 1.5 MB)
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(10000000); // 10 MB
}
);
}
};
}
}
或者配置文件方式
tomcat
server.tomcat.max-http-post-size: 10MB
Jetty
server.jetty.max-http-post-size: 10MB
Undertow
server.undertow.max-http-post-size: 10MB
最后配置文件里 请求大小
spring:
http:
multipart:
maxRequestSize: 100Mb
maxFileSize: 10Mb
最后启动Sb.run
上一篇: 用户,组,文件权限管理