LZ最近升級SpringBoo框架到2.1.6,踩了一些坑,這裏介紹的是文件上傳大小限制。java
#文件上傳配置 1.5.9 spring: http: multipart: enabled: true max-file-size: 100Mb max-request-size:100Mb
##文件上傳配置 2.x spring: servlet: multipart: enabled: true max-file-size: 100Mb max-request-size: 100Mb
咱們能夠從源碼分析,找到SpringBoot的相關源碼——MultipartProperties
類web
package org.springframework.boot.autoconfigure.web.servlet; import javax.servlet.MultipartConfigElement; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.util.StringUtils; @ConfigurationProperties( prefix = "spring.servlet.multipart", ignoreUnknownFields = false ) public class MultipartProperties { private boolean enabled = true; private String location; private String maxFileSize = "1MB"; private String maxRequestSize = "10MB"; private String fileSizeThreshold = "0"; private boolean resolveLazily = false; ......... }
上面是SpringBoot2.x源碼,從上面能夠看出,maxFileSize
,即最大文件大小,默認被限制爲1MB,maxRequestSize
即最大請求大小,默認被限制爲10MB。該類的註解中prefix
=spring.servlet.multipart。spring