今天针对SpringBoot展开了学习:

1.配置maven的pom.xml文件:

1.1手动配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.4</version>
    </parent>
    <groupId>org.example</groupId>
    <artifactId>spring_boot</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>day01_spring_boot_create1</module>
    </modules>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

我们手动配置的操作,继承了spring-boot-starter-parent,并且导入了web相关的依赖spring-boot-starter-web;

1.2使用Spring-initializer

idea提供了对应的Spring-initializer可以方便我们创建SpringBoot项目

这里是可以配置源网站的,可以看到我这里使用的是alibaba的源网站

我们还可以引入不同的依赖;

2.SpringBoot parent和starter

spring-boot-starter-parent是所有的Springboot都要继承的项目

在其中,依赖了一个spring-boot.dependencies,在里面规范了使用的各第三方依赖的版本号

3.SpringBoot的启动类

SpringBoot的启动类一般都会放在项目根目录下:

4.SpringBoot支持的三种服务器

内置tomcat 默认的配置

jetty:更轻量级的服务器

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-jetty</artifactId>
        </dependency>

先把spring-boot-starter-web的tomcat给忽略掉,然后再引入新的服务器依赖

5.SpringBoot配置文件

SpringBoot支持三种配置文件:

application.properties/yml/yaml

默认情况下创建springboot后创建的是properties文件,但是它还可以支持.yml和.yaml文件

我们在补充或者修改springboot的依赖时不需要进行版本设置,因为spring-boot-starter-dependencies中都已经配置好了对应的版本,当然执意要更改不同版本的依赖的话也是可以的,但是不推荐

更多推荐