Springboot文件上传大小设置

springboot的项目,上传文件的时候报了下面的错:

  The field file exceeds its maximum permitted size of 1048576 bytes

按照下面方法修改无果

spring:
    servlet:
      multipart:
        max-file-size: 10MB
        max-request-size: 10MB

成功方法↓↓↓↓

application.yml

multipart:
  maxFileSize: 10MB
  maxRequestSize: 10MB

Application.java

    @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();
    }
原文地址:https://www.cnblogs.com/superslow/p/10877422.html