Spring Boot Configure maxSwallowSize in embedded Tomcat

摘要: In Spring Boot, you can’t configure the embedded Tomcat maxSwallowSize via the common application properties, there is no option like server.tomcat.*.maxSwallowSize

In Spring Boot, you can’t configure the embedded Tomcat maxSwallowSize via the common application properties, there is no option like server.tomcat.*.maxSwallowSize

Solution

To fix it, you need to declare a TomcatEmbeddedServletContainerFactory bean and configure the maxSwallowSize like this :

//...
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
    private int maxUploadSizeInMb = 10 * 1024 * 1024; // 10 MB
    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
            // connector other settings...
            // configure maxSwallowSize
            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
                // -1 means unlimited, accept bytes
                ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        });
        return tomcat;

References

  1. Spring file upload and connection reset issue
  2. common application properties
  3. Spring Boot file upload error handling (Japanase)

上一篇: Oracle PL/SQL – After DELETE Trigger example
下一篇: Eclipse – How to know this class belongs to which JAR
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号