修改springboot内置tomcat上传文件的大小参数

https://blog.csdn.net/persistencegoing/article/details/84376427

报错

Maximum upload size exceeded

the request was rejected because its size (9739444) exceeds the configured maximum (5242880)

上传大小超出限制,springboot默认上传大小小于1M

 

 

修改Spring Boot内置Tomcat的maxPostsize值,在application.yml配置文件中添加以下内容:

server:  
  tomcat:
    max-http-post-size: -1

 或者properties中

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

 

再配置服务的

multipart.maxFileSize=150MB
multipart.maxRequestSize=150MB

在启动类中加入

@Bean
public MultipartConfigElement multipartConfigElement(@Value("${multipart.maxFileSize}")String maxFileSize, @Value("${multipart.maxRequestSize}") String maxRequestSize) {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize(maxFileSize);
    factory.setMaxRequestSize(maxRequestSize);
    return factory.createMultipartConfig();
}

搞定

你可能感兴趣的:(springboot)