我将以前在Tomcat容器中运行的Spring启动应用程序迁移到运行嵌入式Tomcat的Spring Boot应用程序。 我的旧Tomcat配置在server.xml中具有以下配置:
<Connector
executor="tomcatThreadPool"
port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
acceptCount="500"
acceptorThreadCount="2"
maxThreads="150"
maxHttpHeaderSize="32768"
maxHeaderCount="256"
connectionTimeout="20000"
maxKeepAliveRequests="-1"
redirectPort="8443"
useComet="false"
socket.appReadBufSize="87380"
socket.rxBufSize="87380"
socket.performanceConnectionTime="2"
socket.performanceLatency="0"
socket.performanceBandwidth="1"
server="My server"
/>
我能够使用bean
设置大多数属性@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol");
tomcatEmbeddedServletContainerFactory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
AbstractHttp11JsseProtocol<Nio2Channel> handler = (AbstractHttp11JsseProtocol)connector.getProtocolHandler();
handler.setMaxKeepAliveRequests(-1);
handler.setAcceptorThreadCount(2);
handler.setMaxHeaderCount(256);
connector.setRedirectPort(8443);
});
return tomcatEmbeddedServletContainerFactory;
}
和application.xml属性:
server.tomcat.accept-count = 500
server.tomcat.max-threads = 600
server.port = 8080
server.max-http-header-size = 32768
server.connection-timeout = 20000
但我无法弄清楚如何设置这部分
useComet="false"
socket.appReadBufSize="87380"
socket.rxBufSize="87380"
socket.performanceConnectionTime="2"
socket.performanceLatency="0"
socket.performanceBandwidth="1"
server="My server"
有人能帮帮我吗? 谢谢
答案 0 :(得分:5)
试试这个:
connector.setProperty("useComet", Boolean.toString(false));
connector.setProperty("socket.appReadBufSize", "87380");
connector.setProperty("socket.rxBufSize", "87380");
connector.setProperty("socket.performanceConnectionTime", "2");
connector.setProperty("socket.performanceLatency", "0");
connector.setProperty("socket.performanceBandwidth", "1");
connector.setProperty("server", "My server");
答案 1 :(得分:1)
connector.setProperty("socket.appReadBufSize", "87380");
connector.setProperty("socket.rxBufSize", "87380");
connector.setProperty("socket.performanceConnectionTime", "2");
connector.setProperty("socket.performanceLatency", "0");
connector.setProperty("socket.performanceBandwidth", "1");
connector.setProperty("server", "My server");
工作得很好。
但是,检查connector.setProperty的返回值很重要。它试图找到调用每个属性的正确方法,如果找到方法并且设置了属性,则返回true。
不幸的是,connector.setProperty("useComet", Boolean.toString(false));
无法正常工作,并且返回了错误。