【SpringBoot框架学习】Web容器 的切换 详解

Youzg LOGO

SpringBoot 支持的Web容器:

在springBoot框架中,支持了3个Web容器:

Spring Boot支持的Web容器

  • Tomcat(默认使用)
  • Jetty
  • Undertow

这三个容器 各具特色,主要区别如下:

3个Web容器的 区别:

区别:

  • Tomcat:
    我们最熟悉的Web容器
  • Jetty:
    开源的Web容器,它为基于Java的web容器

主要特点

  1. 易用性
  2. 可扩展性
  3. 易嵌入性
  4. Jetty更满足公有云的分布式环境的需求,
    而Tomcat更符合企业级环境
  • Undertow:
    用 Java编写 的 灵活高性能Web服务器,
    基于 NIO高性能 Web 嵌入式服务器

主要特点

  1. 轻量级
  2. 支持http升级
  3. 支持WebScoket
  4. 支持Servlet 3.1
  5. 可嵌入性
  6. 灵活性

切换 Web容器:

切换Web容器,十分方便,
我们只需要导入相应的Maven依赖即可,甚至无需配置

切换为 Jetty容器(Maven依赖导入):

<!-- 切换为 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>

切换为Jetty 展示


切换为 Undertow容器(Maven依赖导入):

<!-- 切换为 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>

切换为Undertow展示

猜你喜欢

转载自www.cnblogs.com/codderYouzg/p/13198512.html