代码之家  ›  专栏  ›  技术社区  ›  Thirumal

在spring boot中上载文件大小限制

  •  2
  • Thirumal  · 技术社区  · 7 年前

    在版本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
    
    1 回复  |  直到 7 年前
        1
  •  16
  •   shareef    6 年前

    作为 Michael Stahorszki 提到

    “B”

    必须是资本

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

    在亚马尔

    spring:    
      servlet:
        multipart:
          max-file-size: ${MAX_FILE_SIZE:8MB}
          max-request-size: ${MAX_REQUEST_SIZE:8MB}
    
        2
  •  0
  •   Sandeep Kumar Troy Daniel    6 年前

    今天我重复了这个错误,尽管我用大写“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上下文中有一些错误。 因此,我认为这是一个错误的消息,然后上下文不能被创建+多部分的选项是给定的。