繁体   English   中英

spring开机上传文件大小限制

[英]upload file size limit in spring boot

在 2.1.0 版本中,spring.servlet.multipart.max-file-size 属性无法绑定 org.springframework.util.unit.DataSize。

Property : spring.servlet.multipart.maxFileSize= 50Mb

例外

Description:

Failed to bind properties under 'spring.servlet.multipart.max-file-size' to org.springframework.util.unit.DataSize:

Property: spring.servlet.multipart.maxfilesize
Value: 50Mb
Origin: "spring.servlet.multipart.maxFileSize" from property source "bootstrapProperties"
Reason: failed to convert java.lang.String to @org.springframework.boot.convert.DataSizeUnit org.springframework.util.unit.DataSize

Action:

Update your application's configuration

正如迈克尔斯塔霍斯基提到的

“乙”

必须是资本

Property : spring.servlet.multipart.maxFileSize= 50MB

在 Yaml 中

spring:    
  servlet:
    multipart:
      max-file-size: ${MAX_FILE_SIZE:8MB}
      max-request-size: ${MAX_REQUEST_SIZE:8MB}

今天我重复了这个错误,虽然我用大写的“B”设置了“MB”:

Description:

Failed to bind properties under 'spring.servlet.multipart.max-file-size' to org.springframework.util.unit.DataSize:

    Property: spring.servlet.multipart.max-file-size
    Value: 300MB 
    Origin: class path resource [application.properties]:27:40
    Reason: failed to convert java.lang.String to org.springframework.util.unit.DataSize

如果我注释掉这个选项应用程序无论如何都不会启动 - spring 上下文中存在一些错误。 所以我认为这是一个错误的错误消息,然后无法创建上下文 + 给出了多部分选项。

在我的例子中,我在大小末尾有多余的空格(在 MB、KB 之后)。 为了解决这个问题,我删除了空格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM