如果出现“连接重置”错误,则问题可能出现在从Tomcat 7.0添加的Tomcat默认连接器maxSwallowSize属性中。55(ChangeLog)
Apache Tomcat 8 Configuration Reference从
maxSwallowSize: The maximum number of request body bytes (excluding transfer encoding overhead) that will be swallowed by Tomcat for an aborted upload. An aborted upload is when Tomcat knows that the request body is going to be ignored but the client still sends it. If Tomcat does not swallow the body the client is unlikely to see the response. If not specified the default of 2097152 (2 megabytes) will be used. A value of less than zero indicates that no limit should be enforced.
对于Springboot嵌入的Tomcat声明一个TomcatEmbeddedServletContainerFactory
爪哇8:
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 for unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
}
爪哇7:
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 for unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
}
});
return tomcat;
}
或者在Tomcat/conf目录/ server.xml中为5MB
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxSwallowSize="5242880" />
我补充这一点:HTTP: 多: maxFileSize为:100兆 maxRequestSize:100Mb的 弹簧部分,但它并没有帮助。 – tibi
@tibi如果您使用Sprint Boot 1.4.x,请检查网站站长的答案,因为此属性已更改。 – AndreLDM