如果出現「連接重置」錯誤,則問題可能出現在從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