快速上手springboot 案例

本文介绍了如何在Spring官网和阿里云上创建Spring Boot项目,重点关注parent依赖管理和starter的依赖传递。同时,解释了引导类的作用以及内嵌Tomcat的配置,包括如何更换应用容器。
摘要由CSDN通过智能技术生成
parent 在spring官网创建项目的途径 start.spring.org

在这里插入图片描述
=》
在这里插入图片描述
=》
在这里插入图片描述
=》
自己不需要指定版本 springboot 给你指定了最好的版本
在这里插入图片描述
spring boot 存储的东西通过paret实现

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath></relativePath>
    </parent>

parent 的version不同 里面的引入的版本也不同
创建俩个pom文件
一个引入2.5.4的parent
在这里插入图片描述
进入下面文件里面在这里插入图片描述再进入 dependencys
在这里插入图片描述
在这里插入图片描述
复制里面的内容 到 pom1文件
在这里插入图片描述

同理
一个引入2.5.0的文件
在这里插入图片描述
复制内容到pom2中 进行比较文件
在这里插入图片描述

在这里插入图片描述

在阿里云上创建的项目 start.aliyun.com
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
starter 依赖传递

一个starter 引入许多依赖
在这里插入图片描述

引导类

SpringApplication.run(DemoApplication.class, args); 是一个容器 下面为解释
创建对象
ConfigurableApplicationContext ctx = SpringApplication.run(DemoApplication.class, args);

ConfigurableApplicationContext ctx = SpringApplication.run(DemoApplication.class, args);
// 获取bean 容器
 BookController bean = ctx.getBean(BookController.class);

在这里插入图片描述

tomcat

pom文件中 进入
在这里插入图片描述
-》
在这里插入图片描述
tomcat 内嵌核心
在这里插入图片描述

如果想换容器 可以先排除默认的容器 在设置一个新的容器
下图设置了 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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值