mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-26 19:20:27 +08:00
定制化内嵌Tomcat开发
This commit is contained in:
parent
683aa24459
commit
cfd3a6f029
@ -0,0 +1,35 @@
|
|||||||
|
package com.cxyxiaomo.flashsale.config;
|
||||||
|
|
||||||
|
import org.apache.catalina.connector.Connector;
|
||||||
|
import org.apache.coyote.ProtocolHandler;
|
||||||
|
import org.apache.coyote.http11.Http11NioProtocol;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||||
|
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
||||||
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当Spring容器内没有TomcatEmbeddedServletContainerFactory这个bean时,会把当前bean加载进Spring容器中
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WebServerConfiguration implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void customize(ConfigurableWebServerFactory factory) {
|
||||||
|
// 使用对应工厂类提供给我们的接口定制化我们的tomcat connector
|
||||||
|
((TomcatServletWebServerFactory)factory).addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||||
|
@Override
|
||||||
|
public void customize(Connector connector) {
|
||||||
|
Http11NioProtocol protocolHandler = (Http11NioProtocol) connector.getProtocolHandler();
|
||||||
|
|
||||||
|
// 定制化 KeepAliveTimeout,设置30秒内没有请求则服务端自动断开KeepAlive连接
|
||||||
|
protocolHandler.setKeepAliveTimeout(30000);
|
||||||
|
|
||||||
|
// 当客户端发送超过10000个请求则自动断开KeepAlive连接
|
||||||
|
protocolHandler.setMaxKeepAliveRequests(10000);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user