Springboot应用程序使用TomcatembedservletContainerFactory vs JetTyembedservletContainerFactory上传大型(2 GB)文件

发布于 2025-01-31 04:50:19 字数 2010 浏览 2 评论 0原文

我的Springboot应用程序使用TomCatembedDedServletContainerFactory上传大(2GB)文件,现在我们不使用的Tomcat依赖性,但目前使用Jetty依赖性。因此,使用JetTyembedDedServletContainerFactory需要设置文件限制 - > Springboot Application.Class中的SetMaxSwallowSize(-1)。

@SpringBootApplication
@ServletComponentScan
@ComponentScan({ "com.abc" })
@EnableAspectJAutoProxy
@EnableScheduling
@EnableAsync
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
@Bean public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
     TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    
     tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> { if
     ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
     //-1 means unlimited ((AbstractHttp11Protocol<?>)
     connector.getProtocolHandler()).setMaxSwallowSize(-1); } });
     }
}

您可以在Springboot应用程序中使用JetTyembeddedservletContainerFactory。

@SpringBootApplication
@ServletComponentScan
@ComponentScan({ "com.abc" })
@EnableAspectJAutoProxy
@EnableScheduling
@EnableAsync
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

@Bean 
    public JettyEmbeddedServletContainerFactory servletContainer() {
        JettyEmbeddedServletContainerFactory factory1 = new JettyEmbeddedServletContainerFactory(); // JettyServerCustomizer
      factory1.setMaxSwallowSize(-1);
      return factory1;
 }
}

My Springboot application used TomcatEmbeddedServletContainerFactory to upload large(2GB) file,now tomcat dependency we are not using, but currently using jetty dependency. So using JettyEmbeddedServletContainerFactory need to set the file limit-> setMaxSwallowSize(-1) in SpringBoot Application.class.

@SpringBootApplication
@ServletComponentScan
@ComponentScan({ "com.abc" })
@EnableAspectJAutoProxy
@EnableScheduling
@EnableAsync
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
@Bean public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
     TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    
     tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> { if
     ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
     //-1 means unlimited ((AbstractHttp11Protocol<?>)
     connector.getProtocolHandler()).setMaxSwallowSize(-1); } });
     }
}

Any one can u please help with using JettyEmbeddedServletContainerFactory in SpringBoot Application.class

@SpringBootApplication
@ServletComponentScan
@ComponentScan({ "com.abc" })
@EnableAspectJAutoProxy
@EnableScheduling
@EnableAsync
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

@Bean 
    public JettyEmbeddedServletContainerFactory servletContainer() {
        JettyEmbeddedServletContainerFactory factory1 = new JettyEmbeddedServletContainerFactory(); // JettyServerCustomizer
      factory1.setMaxSwallowSize(-1);
      return factory1;
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文