SpringBoot切换成其它的嵌入式Servlet容器(Jetty和Undertow)

SpringBoot默认使用的内置Servlet容器是Tomcat
然而 SpringBoot还支持其它的Servlet容器 默认的Tomcat只是其中一种

SpringBoot还支持JettyUndertow

  • Jetty适合用于长链接应用 例如聊天
  • Undertow是一个高性能非阻塞的Servlet容器 并发性能非常好 但不支持jsp

在这里插入图片描述
若要切换 只需要在pom文件中排除自带的Tomcat启动器 再引入其它Servlet容器的启动器即可
spring-boot-starter-web里面引入了spring-boot-starter-tomcat 因此默认使用Tomcat

因此 只需排除原先的Tomcat 再引入要添加的Servlet容器的依赖 即可:

切换成Jetty:

<!-- 引入Web模块 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- 排除tomcat容器 -->
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>
<!-- 引入其它的Servlet容器 -->
<dependency>
    <artifactId>spring-boot-starter-jetty</artifactId>
    <groupId>org.springframework.boot</groupId>
</dependency>

在这里插入图片描述
Jetty启动成功


同理 切换成undertow:

<!-- 引入Web模块 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- 排除tomcat容器 -->
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>
<!-- 引入其它的Servlet容器 -->
<dependency>
    <artifactId>spring-boot-starter-undertow</artifactId>
    <groupId>org.springframework.boot</groupId>
</dependency>

在这里插入图片描述
Undertow启动成功


发布了174 篇原创文章 · 获赞 5 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/Piconjo/article/details/104975479