springboot上传大文件报错

the request was rejected because its size (48376267) exceeds the configured

配置文件已配置以下属性,但报错依然

spring.http.multipart.maxFileSize=1000Mb
spring.http.multipart.maxRequestSize=1000Mb

故使用另一种方法,在启动类中注入:

import javax.servlet.MultipartConfigElement;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, new String[] { "--debug" });
    }

    /**
     * 设置上传文件大小,配置文件属性设置无效
     *
     * @author 空空dream
     * @date 2018年3月8日
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory config = new MultipartConfigFactory();
        config.setMaxFileSize("9000MB");
        config.setMaxRequestSize("9000MB");
        return config.createMultipartConfig();
    }
}

继续上传大文件,不再报错。

你可能感兴趣的:(web)