Skip to content

Instantly share code, notes, and snippets.

@dalesupa22
Created June 9, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalesupa22/2b5f67afd7a8b3a39714 to your computer and use it in GitHub Desktop.
Save dalesupa22/2b5f67afd7a8b3a39714 to your computer and use it in GitHub Desktop.
How to edit the default maxPostSize of embedded Tomcat in SpringBoot
@Bean
EmbeddedServletContainerCustomizer containerCustomizer(
) throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(10000000);//10MB
}
);
}
};
}
@dalesupa22
Copy link
Author

This is very useful because the default config in SpringBoot only allows to upload 2 MB files.

@dalesupa22
Copy link
Author

org.apache.catalina.connector.Request.class line 2779 if (postSize > maxPostSize) {
throw new IllegalStateException(sm.getString(
"coyoteRequest.maxPostSizeExceeded"));
}

@dalesupa22
Copy link
Author

This solves the following exception: Caused by: java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector

@prashanth-g
Copy link

Thanks buddy 👍 Really helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment