It would be convenient if application.yml supported tomcat maxPostSize settings, versus the verbose snippet shown below. (which does enable post params large then 2Mb tomcat default to work).

// stolen from stack overflow
// Set maxPostSize of embedded tomcat server to 10 megabytes 
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
    return (ConfigurableEmbeddedServletContainer container) -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                (connector) -> {
                    connector.setMaxPostSize(10000000); // 10 MB
                }
            );
        }
    };
}

Comment From: philwebb

I wonder if Undertow and Jetty also have equivalent options? It would be nice if we could offer a single property that configured all three.

BTW, if you are just wanting to restrict file uploads you can use multipart.max-file-size=10Mb

Comment From: hzhangx

In Spring boot application-serverConfig.properties add the following line: server.tomcat.max-http-post-size=5000000

Comment From: HimanshuChugh2

Hey ,

The below is no longer valid

@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
    return (ConfigurableEmbeddedServletContainer container) -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                (connector) -> {
                    connector.setMaxPostSize(10000000); // 10 MB
                }
            );
        }
    };
}

how can in write it as per the new updates?? Please help

@peterdnight

Comment From: wilkinsona

@HimanshuChugh2 Judging by https://github.com/spring-projects/spring-boot/issues/18521#issuecomment-668230288, you've already figured this out so I am going to mark your comment as resolved.