目录
一、配置文件
1.1、yaml
YAML是“YAML Ain't Markup Language”的递归缩写。非常适合用来做以数据为中心的配置文件。
1.2、基本语法
1、key:value;kv之间有空格。
2、大小写敏感。
3、使用缩进表示层级关系。
4、缩进不允许使用tab,只允许空格。
5、缩进的空格数不重要,只要相同层级的元素左对齐就行。
6、'#'表示注释。
7、字符串无需加引号,如果要加,"与"表示字符串内容会被转义/不转义。
1.3、数据类型
1、字面量:单个的、不可再分的值。
2、对象:键值对的集合。
3、数组:一组按次序排列的值。
1.4、案例测试
@Data
@ToString
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String userName;
private Boolean boss;
private Date birth;
private Integer age;
private Pet pet;
private String[] interests;
private List<String> animal;
private Map<String, Object> score;
private Set<Double> salarys;
private Map<String, List<Pet>> allPets;
}
@Data
@ToString
public class Pet {
private String name;
private Double weight;
}
person:
userName: laomo
boss: true
birth: 2000/12/12
age: 18
#interests: [卖鱼,送鱼]
interests:
- 卖鱼
- 送鱼
animal: [草鱼,鲤鱼]
#score:
#math: 80
score: {math:80}
salarys:
- 5000.00
- 8900.00
pet:
name: 金龙鱼
weight: 3.00
allPets:
sick:
- {name: 金龙鱼,weight: 3.00}
- name: 草鱼
weight: 4.00
health:
- {name: 银龙鱼,weight: 3.00}
二、配置提示
<!--配置提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!--打包排除-->
<configuration>
<excludes>
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>