SpringBoot Web依赖

本文,主要记录如何切换Springboot内部 web依赖。

在使用SpringBoot时,首先引人注意的便是其启动方式,我们熟知的web项目都是需要部署到服务容器上,例如tomcat、weblogic、widefly(以前叫JBoss) ---小编百度得知,然后启动web容器真正运行我们的系统。而SpringBoot搭建的系统却是运行***Application.class中的main方法启动。这是为什么?

原因是SpringBoot除了高度集成封装了Spring一系列框架之外,还封装了web容器,SpringBoot启动时会根据配置启动相应的上下文环境,查看EmbeddedServletContainerAutoConfiguration源码可知(这里SpringBoot启动过程会单独总结分析)。

正常Tomcat服务启动

SpringBoot Web依赖教程

找到jar包下的内置目录

该自动配置类表明SpringBoot支持封装Tomcat、Jetty和Undertow三种web容器,查看spring-boot-starter-web的pom.xml(如下),其默认配置为Tomcat。

SpringBoot Web依赖教程

分析依赖坐标

SpringBoot Web依赖教程

排除Tomcat依赖

SpringBoot Web依赖教程

pom配置

        <exclusions>
            <exclusion>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <groupId>org.springframework.boot</groupId>
            </exclusion>
        </exclusions>

注意:以上部分会自动生成。做以下跟更改。

 
        <!--web 开发的起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--排除TomCat 依赖-->
            <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 启动的了。

SpringBoot Web依赖教程

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。 

原文地址:https://blog.csdn.net/weixin_40247412/article/details/105743338

相关文章:

  • 2021-11-18
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-08-05
  • 2021-11-10
猜你喜欢
  • 2022-01-27
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2021-06-07
相关资源
相似解决方案