@Configuration public class TomcatConfig { @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } @Bean public ConfigurableServletWebServerFactory configurableServletWebServerFactory() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.addContextCustomizers(context -> { SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); collection.addMethod("PUT"); collection.addMethod("DELETE"); collection.addMethod("OPTIONS"); collection.addMethod("TRACE"); collection.addMethod("COPY"); collection.addMethod("SEARCH"); collection.addMethod("PROPFIND"); securityConstraint.addCollection(collection); context.addConstraint(securityConstraint); }); factory.addConnectorCustomizers(new MyTomcatConnectorCustomizer()); return factory; } class MyTomcatConnectorCustomizer implements TomcatConnectorCustomizer { @Override public void customize(Connector connector) { // 禁用TRACE请求 connector.setAllowTrace(true); Http11NioProtocol handler = (Http11NioProtocol) connector.getProtocolHandler(); //handler.setAcceptCount(1000);// 排队数 //handler.setMaxConnections(1000);// 最大连接数 //handler.setMaxThreads(500);// 线程池的最大线程数 //handler.setMinSpareThreads(50);// 最小线程数 handler.setConnectionTimeout(8000);// 超时时间 20S } } }