47.SpringBoot学习笔记

切换其他嵌入式Servlet容器

Posted by Chen Xingxu on June 20, 2020

47.SpringBoot学习笔记–切换其他嵌入式Servlet容器

替换为其他嵌入式 Servlet 容器

Tomcat(默认使用)

<!--引入web模块默认就是使用嵌入式的Tomcat作为Servlet容器-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Jetty

<!--排除tomcat-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>

<!--引入Jetty-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

通过控制台可以看到:

Jetty started on port(s) 8083 (http/1.1) with context path '/crud'

Undertow

<!--排除tomcat-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>

<!--引入Undertow-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

通过控制台可以看到:

Undertow started on port(s) 8083 (http) with context path '/crud'