在 Spring Boot 中设置 tomcat connectionUploadTimeout [英] Setting tomcat connectionUploadTimeout in Spring Boot

查看:131
本文介绍了在 Spring Boot 中设置 tomcat connectionUploadTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试设置 Tomcat connectionUploadTimeout Spring Boot 2 中的属性.我在我的服务器日志中得到一些随机的不可重现的 java.net.SocketTimeoutException: null.

I want to try to set the Tomcat connectionUploadTimeout property within Spring Boot 2. I'm getting some random non-reproducible java.net.SocketTimeoutException: null in my server logs.

它来自请求输入流,所以如果我可以将此属性设置为非常短的持续时间,那么我应该能够在本地复制它.

It's coming from the request input stream, so if I can set this property to a really short duration, then I should be able to replicate it locally.

我试过了

server.disableUploadTimeout=false
server.connectionUploadTimeout=5000

server.tomcat.disableUploadTimeout=false
server.tomcat.connectionUploadTimeout=5000

server.tomcat.disable-upload-timeout=false
server.tomcat.connection-upload-timeout=5000

但我在本地的 15 秒请求仍在完成,没有任何超时.

but still my 15 seconds requests locally are completing without any time-outs.

Spring 文档在这里不是很有帮助.

推荐答案

无需猜测支持哪些属性,因为它们都列在 参考文档中的附录.正如您希望看到的,没有用于配置连接上传超时或在 Connector 上启用上传超时的属性.这意味着必须以编程方式配置这些属性.

There's no need to guess which properties are supported as they're all listed in an appendix in the reference documentation. As you can hopefully see, there are no properties for configuring the connection upload timeout or for enabling the upload timeout on a Connector. This means that those properties must be configured programatically.

您可以使用特定于 Tomcat 的 WebServerFactoryCustomizer 以编程方式配置 Connector:

You can configure the Connector programmatically using a Tomcat-specific WebServerFactoryCustomizer:

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
    return (tomcat) -> tomcat.addConnectorCustomizers((connector) -> {
        if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
            AbstractHttp11Protocol<?> protocolHandler = (AbstractHttp11Protocol<?>) connector
                    .getProtocolHandler();
            protocolHandler.setDisableUploadTimeout(false);
            protocolHandler.setConnectionUploadTimeout(5000);
        }
    });
}

这篇关于在 Spring Boot 中设置 tomcat connectionUploadTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆