zoukankan      html  css  js  c++  java
  • springboot 内置tomcat设置

    @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
    
            }
        }
    
    }
  • 相关阅读:
    MyBatis使用
    华为如何实现基于Git的跨地域协同开发
    推荐一款华为最新的自动化代码检查工具
    我是如何进行code review的
    谈谈敏捷开发
    软件测试管理的一点小心得
    (转)技术转管理可能遇到的 3 大挑战及解决方案
    领域驱动设计和实践
    NET开源项目
    asp.net搭建mybatis开发环境
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/14293415.html
Copyright © 2011-2022 走看看