首页 > 解决方案 > 在 ECS 上部署时出现 MultipartException - Spring 1.5.15.RELEASE

问题描述

我正面临一个非常奇怪的行为。我正在将我的 jar 打包到一个容器中以将其部署在 ECS 上,但是,在将max-file-size定义为100M时,我的 application.yaml 似乎没有生效。

奇怪的是,当在本地或通过执行 fat jar 启动应用程序时,它工作得很好。

这是我的application.yaml

spring:
  http.multipart:
    max-file-size: 100MB
    max-request-size: 100MB

Dockerfile

FROM openjdk:8-jre-alpine
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=prod","-jar","/app.jar"]

AWS 上的错误

{
  "timestamp": 1535489967123,
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.springframework.web.multipart.MultipartException",
  "message": "Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (43258070) exceeds the configured maximum (10485760)",
  "path": "/fake/path/loader"
}

标签: amazon-web-servicesspring-bootamazon-ecs

解决方案


问题主要在于您的 application.yaml 没有正确打包。作为替代方案,您可以按照以下方式为您的 spring jar 使用命令行覆盖:

java -jar your-app.jar --spring.http.multipart.max-file-size=100MB --spring.http.multipart.max-request-size=100MB

或者您可以参考此答案中提到的外部应用程序文件加载: 外部应用程序道具


推荐阅读