SpringBoot3入门第一章

现状

俗话说,买新不买旧,学技术也一样,学最新的技术,因为时代会给先行者最为优厚的回报

第一章 构建SpringBoot项目

这个因为太久没有用SpringBoot,导致好多东西都忘记了,就很烦
在这里插入图片描述
好在这里面东西并不多,这玩意启动很简单
默认访问的端口,要背一下

http://localhost:8080/

测试返回hello请求成功,在经过下文的代码修改后

http://localhost:8080/hello


在这里插入图片描述

第二章 代码结构

在这里插入图片描述
在这里插入图片描述

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@Controller
public class HelloController {
    
    
    @GetMapping("/hello")
    public String hello(){
    
    


        return "Hello,Spring Boot 3";
    }
}
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MainApplication {
    
    

    public static void main(String[] args) {
    
    
        SpringApplication.run(MainApplication.class, args);
    }

}

打包测试:fat-jar 大体积jar包

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

先点clean,后点package,生成一个jar包
在这里插入图片描述

三 SpringBoot框架的特性

1. 简化整合

导入相关的场景,拥有相关的功能。场景启动器
默认支持的所有场景:https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.starters
● 官方提供的场景:命名为:spring-boot-starter-*
● 第三方提供场景:命名为:*-spring-boot-starter

场景一导入,万物皆就绪

2. 简化开发

无需编写任何配置,直接开发业务

3. 简化配置

application.properties:
● 集中式管理配置。只需要修改这个文件就行 。
● 配置基本都有默认值
● 能写的所有配置都在: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties

4. 简化部署

打包为可执行的jar包。
linux服务器上有java环境。

5. 简化运维

修改配置(外部放一个application.properties文件)、监控、健康检查。

猜你喜欢

转载自blog.csdn.net/CNMBZY/article/details/132288441