本文参考https://c.biancheng.net/spring_boot/example.html
SpringBoot
starter
Spring Boot 将日常企业应用研发中的各种场景都抽取出来,做成一个个的 starter(启动器),starter 中整合了该场景下各种可能用到的依赖,用户只需要在 Maven 中引入 starter 依赖,SpringBoot 就能自动扫描到要加载的信息并启动相应的默认配置。start由springboot官方提供,或者第三方提供,也当然也存在个别第三方技术,Spring Boot 官方没提供 starter,第三方技术厂商也没有提供 starter。
spring-boot-starter-parent
spring-boot-starter-parent 是所有 Spring Boot 项目的父级依赖,它被称为 Spring Boot 的版本仲裁中心,可以对项目内的部分常用依赖进行统一管理。
特性:
- 默认 JDK 版本(Java 8)
- 默认字符集(UTF-8)
- 依赖管理功能
- 资源过滤
- 默认插件配置
- 识别 application.properties 和 application.yml 类型的配置文件
YAML教程(快速入门版)
想要使用 YAML 作为属性配置文件(以 .yml 或 .yaml 结尾),需要将 SnakeYAML 库添加到 classpath 下,Spring Boot 中的 spring-boot-starter-web 或 spring-boot-starter 都对 SnakeYAML 库做了集成, 只要项目中引用了这两个 Starter 中的任何一个,Spring Boot 会自动添加 SnakeYAML 库到 classpath 下。
YAML 的语法如下:
1.使用缩进表示层级关系。
2.缩进时不允许使用 Tab 键,只允许使用空格。
3.缩进的空格数不重要,但同级元素必须左侧对齐。
4.大小写敏感。
YAML 字面量写法
字面量是指单个的,不可拆分的值,例如:数字、字符串、布尔值、以及日期等。
在 YAML 中,使用“key:[空格]value”的形式表示一对键值对(空格不能省略),如 url: www.biancheng.net。
字面量直接写在键值对的“value”中即可,且默认情况下字符串是不需要使用单引号或双引号的。若字符串使用单引号,则会转义特殊字符。
YAML 对象写法
在 YAML 中,对象可能包含多个属性,每一个属性都是一对键值对。
YAML 为对象提供了 2 种写法:
-
普通写法,使用缩进表示对象与属性的层级关系,如:
website:
name: bianchengbang
url: www.biancheng.net -
行内写法
website: {name: bianchengbang,url: www.biancheng.net}
YAML 数组写法
-
YAML 使用“-”表示数组中的元素,普通写法如下:
pets:
-dog
-cat
-pig -
行内写法
pets: [dog,cat,pig]
properties
springboot可以自动识别properties文件
# 数据库配置spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=root
spring.datasource.password=password# 服务器端口
server.port=8080