zoukankan      html  css  js  c++  java
  • 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依赖就可以

  • 相关阅读:
    设计模式(十六):职责链模式
    设计模式(十五):状态模式
    设计模式(十四):命令模式
    设计模式(十三):模板模式
    设计模式(十二):观察者模式
    远程连接数据库常出现的错误解析
    [解决] Error Code: 1044. Access denied for user 'root'@'%' to database
    linux常用命令
    linux上svn项目管理,同步服务器,用户管理
    linux 磁盘分区
  • 原文地址:https://www.cnblogs.com/vegeta-xiao/p/12509962.html
Copyright © 2011-2022 走看看