SpringBoot
1、简介
1.1、SpringBoot
约定大于配置
框架
1.2、微服务
架构风格
https://www.sohu.com/a/221400925_100039689
2、第一个SpringBoot程序
2.1、网页构建
或IDEA中构建
2.2、代码结构
生成jar包可直接执行
2.3、配置
自定义banner
修改项目端口号
3、原理
自动配置:
pom.xml
- spring-boot-dependencies:核心依赖在父工程中
- 在引入SpringBoot依赖的时候,不需要指定版本,就是因为有这些版本仓库
启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- SpringBoot的启动场景
- 如spring-boot-starter-web会帮我们自动导入web环境所有的依赖
- springboot会将所有的功能场景,变成一个个启动器
主程序
//标注这个类是SpringBoot的应用
@SpringBootApplication
public class Springboot02Application {
//启动SpringBoot程序
public static void main(String[] args) {
SpringApplication.run(Springboot02Application.class, args);
}
}
- 注解
@SpringBootConfiguration SpringBoot配置
@Configuration spring配置类
@Component spring组件
@EnableAutoConfiguration 自动配置
@AutoConfigurationPackage 自动配置包
@Import({Registrar.class}) 导入注册器
@Import({AutoConfigurationImportSelector.class})
4、配置
4.1、yaml
# 对空格的要求高
# key-value
name: dd
# 对象
student:
name: dd
age: 3
student2: {name: ddd ,age: 3}
#数组
pet:
- cat
- dog
pet2: [cat,dog]
4.2、yaml给实体类赋值
4.3、配置多环境
5、SpringBoot Web开发
- 前端
- 设计数据库
- 前端自动运行,独立化工程
- 数据接口如何对接:json
- 前后端联调测试
6、SpringSecurity
安全框架