【问题标题】:SpringBoot 2.0 - FileSizeLimitExceededException even with correct parameters setSpringBoot 2.0 - FileSizeLimitExceededException 即使设置了正确的参数
【发布时间】:2018-08-17 13:04:08
【问题描述】:

我已经在 application.yml 中设置了这些参数:

spring:
  servlet:
    multipart:
      max-file-size: -1
      max-request-size: -1

当我从 IDE 运行它时,它工作正常。当我尝试将它与 spring cloud、netflix eureka 和 zuul proxy 一起运行时,问题就开始了。它的行为就像没有这样的参数。它总是抛出:

"超出最大上传大小;嵌套异常是 java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: 字段文件超出了其允许的最大大小 1048576 字节。",

我应该把它放在别的地方吗?

编辑: 我的 bootstrap.yml

spring:
  profiles: docker
  application:
    name: test-service
  sleuth:
    sampler:
      probability: 1
  zipkin:
    base-url: http://zipkin:9411/
  cloud:
      config:
        discovery:
          enabled: true
          service-id: config-server
        fail-fast: true
        retry:
          initial-interval: 2000
          max-interval: 10000
          multiplier: 2
          max-attempts: 10

eureka:
  instance:
    hostname: test-service
    prefer-ip-address: true
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-server:8761/eureka/

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

logging:
  file: ./logs/log.log

【问题讨论】:

  • 你也有 bootstrap.yml 吗?
  • 在我看来是不同版本的 Spring Boot 的类路径问题。1) 检查您的 Spring Cloud 依赖项版本,它们可能引入了旧版本的 Spring Boot。 2)检查你的spring cloud版本是否与spring boot 2兼容
  • 如果你使用 maven 作为构建系统,你可以使用 mvn dependency:tree 命令来查看你的有效 pom
  • @Arnaud 我已经用 bootstrap.yml 更新了我的帖子
  • @AnilBachola Spring boot 有 2.0.4 版本,cloud 是 Finchley.RELEASE

标签: java microservices spring-cloud netflix-zuul netflix-eureka


【解决方案1】:

遇到同样的问题并找到了解决方案,将其发布在这里 3 年后仍然有人需要帮助。

如果您的流量流经 Netflix Zuul 边缘服务,您应该更新 Zuul 和文件上传应用程序服务中的以下属性。

用于spring boot 2.x及以上

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 2015-07-25
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多