Jordan Jordan - 2 years ago 772
Java Question

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

. 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
value is 2 megabytes. Is there any way to edit this value? Doing so via
would be best, rather than having to create customized beans or mess with xml files.

Answer Source

Found a solution. Add this code to the same class running

// Set maxPostSize of embedded tomcat server to 10 megabytes (default is 2 MB, not large enough to support file uploads > 1.5 MB)
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
    return (ConfigurableEmbeddedServletContainer container) -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
                (connector) -> {
                    connector.setMaxPostSize(10000000); // 10 MB

Edit: Apparently adding this to your file will also increase the maxPostSize, but I haven't tried it myself so I can't confirm.

multipart.maxFileSize=10Mb # Max file size.
multipart.maxRequestSize=10Mb # Max request size.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download