开发环境
名称 | 版本 |
---|---|
操作系统 | Windows 10 X64 |
IntelliJ IDEA | 2023.1.2 (Ultimate Edition) |
Maven | 3.6.0 |
创建空项目
项 | 值 |
---|---|
名称 | SpringBoot3-Study |
位置 | D:\Study-Java\2023 |
创建模块
项 | 值 |
---|---|
名称 | boot3-01-demo |
位置 | D:\Study-Java\2023\SpringBoot3-Study |
语言 | Java |
构建系统 | Maven |
JDK | 版本:17 供应商:Eclipse Temurin(AdoptOpenJDK HotSpot)17.0.8 位置:C:\Users\Administrator.jdks\temurin-17.0.8 |
主 ID | com.atguigu |
工件 ID | boot3-01-demo |
boot3-01-demo
pom.xml
创建项目
<!-- 所有springboot项目都必须继承自 spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
</parent>
导入场景
<dependencies>
<!--web开发的场景启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
主程序-MainApplication
package com.atguigu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //这是一个SpringBoot应用
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
Controller
package com.atguigu.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "Hello,Spring Boot 3!";
}
}
测试
- 启动 MainApplication
- 访问:http://localhost:8080/hello
- 输出:
Hello,Spring Boot 3!
打包
- pom.xml
<!-- SpringBoot应用打包插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
mvn clean package
把项目打成可执行的jar
包这里我打包到
D:\Study-Java\2023\SpringBoot3-Study\boot3-01-demo\target\boot3-01-demo-1.0-SNAPSHOT.jar
boot3-01-demo-1.0-SNAPSHOT.jar
复制到D:\Data\boot3-01-demo-1.0-SNAPSHOT.jar
java -jar boot3-01-demo-1.0-SNAPSHOT.jar
启动项目- 输出:
Hello,Spring Boot 3!
特性小结
1.简化整合
导入相关的场景,拥有相关的功能。场景启动器
- 官方提供的场景:命名为:
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
文件)、监控、健康检查。 - …..