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();
    }

 

posted @ 2019-05-16 19:02  阿衰问问  阅读(266)  评论(0编辑  收藏  举报