Spring Boot: ClassNotFoundException when configuring maxUploadSize of CommonMultipartResolver

后端 未结 4 1954
庸人自扰
庸人自扰 2020-12-13 11:12

I\'m using Spring Boot for my web application and I\'m trying to configure the maxUploadSize of Spring\'s CommonMultipartResolver. Currently, it seems to be limited by a Spr

相关标签:
4条回答
  • 2020-12-13 11:44

    for Spring Boot 2.0+ use spring.servlet instead of spring.http

    spring.servlet.multipart.max-file-size=30MB
    spring.servlet.multipart.max-request-size=30MB
    
    0 讨论(0)
  • 2020-12-13 11:48
    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize("5120MB");
        factory.setMaxRequestSize("5120MB");
        return factory.createMultipartConfig();
    }
    

    Try adding this in the class where you are defining beans.

    0 讨论(0)
  • 2020-12-13 11:57

    With spring-boot 1.5.3 you should use the following code in application.yml

    spring:
     http:
      multipart:
       max-file-size: 10MB
       max-request-size: 10MB
    
    0 讨论(0)
  • 2020-12-13 11:58

    You are making it way to complex.

    Just add spring.http.multipart.maxFileSize to your application.properties file and well that is it. No need to use xml or explicitly define a MultipartResolver.

    spring.http.multipart.maxFileSize=10MB   
    

    This is explained in the section about file uploads in the Spring Boot Reference Guide.

    For all properties check the MultipartProperties class. The other properties supported are spring.http.multipart.location, spring.http.multipart.maxRequestSize and spring.http.multipart.fileSizeThreshold.

    The ClassNotFoundException is due to the fact that Spring Boot uses the default Servlet 3.0 support for file uploads NOT commons-fileupload. So if you want to use that, you would have to explicitly add the dependency for it. And ofcourse the spring.http.multipart.* properties don't work anymore in that case.

    0 讨论(0)
提交回复
热议问题