• springboot嵌入式Servlet容器自动配置原理


    @Configuration(proxyBeanMethods = false)
    @ConditionalOnWebApplication
    @EnableConfigurationProperties(ServerProperties.class)
    public class EmbeddedWebServerFactoryCustomizerAutoConfiguration {
    
        /**
         * 如果容器中有Tomcat.class就使用tomcat容器
         */
        @Configuration(proxyBeanMethods = false)
        @ConditionalOnClass({ Tomcat.class, UpgradeProtocol.class })
        public static class TomcatWebServerFactoryCustomizerConfiguration {
    
            @Bean
            public TomcatWebServerFactoryCustomizer tomcatWebServerFactoryCustomizer(Environment environment,
                    ServerProperties serverProperties) {
                return new TomcatWebServerFactoryCustomizer(environment, serverProperties);
            }
    
        }
    
        /**
         * 如果容器中有Jetty
         */
        @Configuration(proxyBeanMethods = false)
        @ConditionalOnClass({ Server.class, Loader.class, WebAppContext.class })
        public static class JettyWebServerFactoryCustomizerConfiguration {
    
            @Bean
            public JettyWebServerFactoryCustomizer jettyWebServerFactoryCustomizer(Environment environment,
                    ServerProperties serverProperties) {
                return new JettyWebServerFactoryCustomizer(environment, serverProperties);
            }
    
        }
    
        /**
         * 如果容器中有Undertow就加载Undertow
         */
        @Configuration(proxyBeanMethods = false)
        @ConditionalOnClass({ Undertow.class, SslClientAuthMode.class })
        public static class UndertowWebServerFactoryCustomizerConfiguration {
    
            @Bean
            public UndertowWebServerFactoryCustomizer undertowWebServerFactoryCustomizer(Environment environment,
                    ServerProperties serverProperties) {
                return new UndertowWebServerFactoryCustomizer(environment, serverProperties);
            }
    
        }
    
        /**
         * Nested configuration if Netty is being used.
         */
        @Configuration(proxyBeanMethods = false)
        @ConditionalOnClass(HttpServer.class)
        public static class NettyWebServerFactoryCustomizerConfiguration {
    
            @Bean
            public NettyWebServerFactoryCustomizer nettyWebServerFactoryCustomizer(Environment environment,
                    ServerProperties serverProperties) {
                return new NettyWebServerFactoryCustomizer(environment, serverProperties);
            }
    
        }
    
    }

    springboot-web模块默认依赖tomca,修改内置servlet,引入其他依赖并删除tomcat依赖就可以

  • 相关阅读:
    剑指 Offer 25. 合并两个排序的链表
    剑指 Offer 26. 树的子结构
    剑指 Offer 27. 二叉树的镜像
    剑指 Offer 29. 顺时针打印矩阵
    剑指 Offer 30. 包含min函数的栈
    剑指 Offer 22. 链表中倒数第k个节点
    选轻量应用服务器还是云服务器ECS?一图彻底搞懂
    征文投稿丨使用云服务器ECS快速搭建halo博客
    运营给产品送的情人节礼物是?
    阿里云张献涛:自主最强DPU神龙的秘诀
  • 原文地址:https://www.cnblogs.com/vegeta-xiao/p/12509962.html
Copyright © 2020-2023  润新知