zoukankan      html  css  js  c++  java
  • springboot不使用内置tomcat启动,用jetty或undertow

    Spring Boot启动程序通常使用Tomcat作为默认的嵌入式服务器如果需要更改 - 您可以排除Tomcat依赖项并改为包含Jetty或Undertow:

    jetty配置:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
    @Bean
    public JettyEmbeddedServletContainerFactory  jettyEmbeddedServletContainerFactory() {
        JettyEmbeddedServletContainerFactory jettyContainer = 
          new JettyEmbeddedServletContainerFactory();
         
        jettyContainer.setPort(9000);
        jettyContainer.setContextPath("/springbootapp");
        return jettyContainer;
    }

    undertow配置:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>
    @Bean
    public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
        UndertowEmbeddedServletContainerFactory factory = 
          new UndertowEmbeddedServletContainerFactory();
         
        factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
            @Override
            public void customize(io.undertow.Undertow.Builder builder) {
                builder.addHttpListener(8080, "0.0.0.0");
            }
        });
         
        return factory;
    }

    9.在引导应用程序中配置Jetty或Undertow

    Spring Boot启动程序通常使用Tomcat作为默认的嵌入式服务器如果需要更改 - 您可以排除Tomcat依赖项并改为包含Jetty或Undertow:

    配置Jetty

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    @Bean
    public JettyEmbeddedServletContainerFactory  jettyEmbeddedServletContainerFactory() {
        JettyEmbeddedServletContainerFactory jettyContainer =
          new JettyEmbeddedServletContainerFactory();
         
        jettyContainer.setPort(9000);
        jettyContainer.setContextPath("/springbootapp");
        return jettyContainer;
    }

    配置Undertow

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    @Bean
    public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
        UndertowEmbeddedServletContainerFactory factory =
          new UndertowEmbeddedServletContainerFactory();
         
        factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
            @Override
            public void customize(io.undertow.Undertow.Builder builder) {
                builder.addHttpListener(8080, "0.0.0.0");
            }
        });
         
        return factory;
    }
  • 相关阅读:
    android手机推送消息 (百度云推送)
    android小功能:checkbox使用自己的背景点击切换背景
    Android中的通知—Notification
    Android判断网络状态
    android简单的夜间模式
    Xutils请求服务器json数据与下载文件
    Android第三方登录详解2
    stackstorm docker中配置ssh免密码登录方式
    scrapy 采集网页出现丢失url的问题
    pandans导出Excel并将数据保存到不同的Sheet表中
  • 原文地址:https://www.cnblogs.com/yunqing/p/10615574.html
Copyright © 2011-2022 走看看