zoukankan      html  css  js  c++  java
  • Spring Boot – Jetty配置

    前言

    默认情况下,Spring Boot会使用内置的tomcat容器去运行应用程序,但偶尔我们也会考虑使用Jetty去替代Tomcat;
    对于Tomcat和Jetty,Spring Boot分别提供了对应的starter,以便尽可能的简化我们的开发过程;
    当我们想使用Jetty的时候,可以参考以下步骤来使用。

    添加spring-boot-starter-jetty依赖

    我们需要更新pom.xml文件,添加spring-boot-starter-jetty依赖,同时我们需要排除spring-boot-starter-web默认的spring-boot-starter-tomcat依赖,如下所示:

    <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>

    如果我们的工程是使用Gradle构建的话,可以使用以下方式达到同样的效果:

    configurations {
        compile.exclude module: "spring-boot-starter-tomcat"
    }
     
    dependencies {
        compile("org.springframework.boot:spring-boot-starter-web:2.0.0.BUILD-SNAPSHOT")
        compile("org.springframework.boot:spring-boot-starter-jetty:2.0.0.BUILD-SNAPSHOT")
    }

    重启完成之后,再次查看控制台打印的日志信息,Jetty started,以此可以确定替换jetty成功

  • 相关阅读:
    DS博客作业02--栈和队列
    DS博客作业02--线性表
    c博客06-2019-结构体&文件
    C博客作业05--2019-指针
    C语言博客作业04--数组
    C语言博客作业03--函数
    JAVA作业-.图书馆查书、借书、还书
    JAVA购物车
    5-互评-OO之接口-DAO模式代码阅读及应用
    DS博客作业05--查找
  • 原文地址:https://www.cnblogs.com/-flq/p/10441706.html
Copyright © 2011-2022 走看看