user1317422
user1317422

Reputation: 257

Setting a tomcat property using spring boot application properties

I want to set the maxSwallowSize property for boot supplied tomcat. My application.properties has this line:

server.context-parameters.maxSwallowSize=20971520 

Doesn't work for some reason. Other properties like server.port work well. Debugging the creation in TomcatEmbeddedServletContainerFactory I see that there is a ServletContexInitializer (InitParameterConfiguringServletContextInitializer) with this property but it doesn't seem to be used in any way. (Even though it's in a variable name initializersToUse, ironic ;p)

I don't like the kill of a connection when the upload exceeds the max size set by

multipart.max-request-size=10MB
multipart.max-file-size=2MB

Is this the correct way of setting this property? During debuggin I can see that the IdentityInputFilter has the default value of 2MB.

newest version of org.springframework.boot:spring-boot-starter-web

Upvotes: 3

Views: 8826

Answers (4)

Ulysse_118
Ulysse_118

Reputation: 19

Putting the right configuration in application.properties or application.yml has been enough for me. But, as detailed in this post, the name of the configuration depends on the Spring Boot version.

In my case, a version later than Spring Boot 2.0.

spring.servlet.multipart.max-file-size=10MB 
spring.servlet.multipart.max-request-size=11MB

Upvotes: 0

AbstractVoid
AbstractVoid

Reputation: 4000

Configuration spring.http.multipart.max-request-size is not the same as maxSwallowSize. The former configures the application and the latter configures the Tomcat server.

So in addition to spring.http.multipart configuration you also should provide configuration for maxSwallowSize, which can simply be done for Spring Boot 2 by setting application property:

server.tomcat.max-swallow-size=100MB

Upvotes: 2

Alexander P.
Alexander P.

Reputation: 51

The configuration like above didn’t help me(I’m using Spring Boot 1.5.10)

I found that the solution was to set

application.properties:

spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB

and all uploads works OK without configurating Tomcat.

Upvotes: 2

Stephane Nicoll
Stephane Nicoll

Reputation: 33101

server.context-parameters (as defined in the documentation can be used to specify the init parameters of the servlet context). maxSwallowSize is a property of the connector. That's a different thing I guess.

We don't have an explicit property for that but you can always configure it via your own TomcatEmbeddedServletContainerFactory.

@Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        protected void customizeConnector(Connector connector) {
            super.customizeConnector(connector);
            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
                (AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(value);
            }
        }
    };

}

Upvotes: 10

Related Questions