Error resolution

[Spring boot | Tomcat error] maxPostSize / 대용량 String post로 전송하는 방법

keepbang 2021. 5. 13. 22:04

post api의 처리되는 데이터 최대 사이즈를 알아보자!!

 

test tool : Postman
os : centos 7
was : tomcat

 

먼저 아무런 설정없이 10MB짜리 String데이터를 만든 후 데이터를 전송해봤다.

그 결과 아래와같은 에러가 나왔다.

org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (11315105) exceeds the configured maximum (10485760)

 

에러를 보면 아무것도 설정안했을때 기본 최대 사이즈는 10485760이라는 걸 알 수 있다.

먼저 spring boot 설정파일을 변경해준다.

아래링크를 참고해서 변경했다.

 

 

 

Increase HTTP Post maxPostSize in Spring Boot

I've got a fairly simple Spring Boot web application, I have a single HTML page with a form with enctype="multipart/form-data". I'm getting this error: The multi-part request contained parameter...

stackoverflow.com

 

spring boot properties file
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=30MB

spring boot yaml file
spring:
  servlet:
    multipart:
      max-file-size: 30MB
      max-request-size: 30MB

 

오른쪽 값을 -1로 설정하면 무한으로 설정되는것같다.

설정 후 실행했을때 또 에러가 나온다.

org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector

마지막으로 tomcat 디렉토리에서 server.xml파일 설정을 해준다.

server.xml에서 connector 태그를 찾아서 maxPostSize를 설정한다.

 

...

<Connector port="8080" protocol="HTTP/1.1"

     maxPostSize="30000000"

...

 

 

 

Apache Tomcat 8 Configuration Reference (8.5.66) - The HTTP Connector

This Connector supports all of the required features of the HTTP/1.1 protocol, as described in RFCs 7230-7235, including persistent connections, pipelining, expectations and chunked encoding. If the client supports only HTTP/1.0 or HTTP/0.9, the Connector

tomcat.apache.org

tomcat 8.5 문서를 찾아보면 maxPostSize에대한 설명이 나와있다.