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 data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector.
I'm using Spring Boot's default embedded tomcat server. Apparently the default maxPostSize
value is 2 megabytes. Is there any way to edit this value? Doing so via application.properties
would be best, rather than having to create customized beans or mess with xml files.
First, make sure you are using
spring.servlet
instead ofspring.http
.If you have to use tomcat, you might end up creating EmbeddedServletContainerCustomizer, which is not really nice thing to do.
If you can live without tomat, you could replace tomcat with e.g. undertow and avoid this issue at all.
In application.properties file write this:
adjust size according to your need.
Update
Note: As of Spring Boot 2, however you can now do
Appendix A. Common application properties - Spring
If you are using using x-www-form-urlencoded mediatype in your POST requests (as I do), the multipart property of spring-boot does not work. If your spring-boot application is also starting a tomcat, you need to set the following property in your application.properties file:
I could not find that information anywhere in the spring-boot documentations. Hope it helps anybody who also sticks with x-www-form-urlencoded encoding of the body.
Found a solution. Add this code to the same class running SpringApplication.run.
Edit: Apparently adding this to your application.properties file will also increase the maxPostSize, but I haven't tried it myself so I can't confirm.
For me nothing of previous works (maybe use application with yaml is an issue here), but get ride of that issue using that:
There is some difference when we define the properties in the
application.yaml
andapplication.properties
.In
application.yml
:And in
application.propeties
:Note: Spring version 4.3 and Spring boot 1.4