• Spring Boot 3 新特性及快速使用示例


    Spring Boot 3

    截止2022年7月28日发版4个里程碑版本

    新特性

    1、最低要求

    要求说明
    JDKJDK 17兼容JDK 18
    SpringSpring Framework 6.0.0或更高版本
    Maven3.5+
    servlet5.0+
    Tomcat10.0
    IntelliJ IDEA2021.2.1

    2、删除的支持

    • Apache ActiveMQ
    • Atomikos
    • EhCache 2
    • Hazelcast 3

    3、Spring boot 2.x中丢弃的

    在 Spring Boot 2.x 中不推荐使用的类、方法和属性已在此版本中删除。请确保在升级之前您没有调用过时的方法。

    4、依赖包的升级

    很多相关的包,就不一一列出来了

    示例演示

    准备

    同时存在2个版本JDK

    因为大部分人自己电脑上使用的是JDK 1.8,想要试用Spring Boot 3必须JDK 17,那边就要配置一下2个JDK版本共存来试用。
    1、下载
    https://www.oracle.com/java
    下载JDK 17安装
    2、配置环境
    新建2个系统环境变量

    环境变量操作类型
    jdk1.8新增
    jdk17新增
    JAVA_HOME修改%jdk17%

    要使用其他JDK版本时,修改JAVA_HOME的值%%中的值即可。

    不同版本说明

    在这里插入图片描述
    M 表示里程碑版本,RC 表示候选发布版本,SNAPSHOT 表示构建

    • GA:General Availability,正式发布的版本,官方推荐使用此版本
    • SNAPSHOT:快照版,可以稳定使用,且仍在继续改进版本
    • PRE:预览版,内部测试版,主要是给开发人员和测试人员测试和找BUG用的,不建议使用
    • M:里程碑版本,可能不完整,但可能仍然有问题

    示例

    IDEA 配置JDK 17

    在这里插入图片描述

    新建Spring Boot 3工程

    在这里插入图片描述
    如图选择点击完成就自动生成相关代码。
    其中pom.xml文件中的如下:

    <?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 https://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>3.0.0-SNAPSHOT</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.lutong</groupId>
        <artifactId>demo3</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>demo3</name>
        <description>demo3</description>
        <properties>
            <java.version>17</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
        <repositories>
            <repository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
    
    </project>
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79

    编写测试Controller类

    package com.lutong.demo3;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * @author lutong
     */
    @RestController
    public class TestController {
        @GetMapping("/hello")
        public String show() {
            return "Hello Spring Boot 3 !";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    运行效果

    在这里插入图片描述

    常见错误

    Error:Cannot determine path to 'tools.jar' library for 17 (C:/Java/jdk-17.0.1)
    
    • 1

    IDEA不支持JDK17,请使用IDEA 2021.2.1及以上版本

  • 相关阅读:
    PostgreSQL 10.23 安装图文教程
    Tomcat容器结构 = 四大容器 + 连接器
    istio安装文档
    Ant Design Mobile 5.6.0版本来了
    Go代码格式化——gofmt的使用
    如何避免重复创建线程?创建线程池的方式有哪些?各自优缺点有哪些?
    m超外差单边带接收机的simulink仿真
    如何做好外贸独立站
    SpringBoot集成Kafka——如此简单
    阿里云服务器x86计算架构ECS实例规格汇总
  • 原文地址:https://blog.csdn.net/luwei42768/article/details/126041590