Springboot应用程序使用TomcatembedservletContainerFactory vs JetTyembedservletContainerFactory上传大型(2 GB)文件
我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论