一.配置文件
- properties
- yaml
- 键:(空格)值
- 缩进(空格,tab)表示层级关系,相同层级对齐
- 字符串不需要加双引号
- 字面量直接写
- 对象需要缩进层级关系
- 数组 -(空格)数据
- 解析单引号双引号
- 单引号中加入\n 会作为字符串输出
- 双引号中加入\n 会作为换行输出
- 双引号不转义(正常用),单引号转义(变普通)
- 实例yaml
@ConfigurationProperties(prefix="person")
@Component
@Data
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
public class Pet {
private String name;
private Double weight;
}
person.userName=xxx
#初始化对象
person:
userName: zhangsan
boss: false
birth: 2019/12/12 20:12:33
age: 18
pet:
name: tomcat
weight: 23.4
#初始化数组[]
interests: [篮球,游泳]
#初始化列表 -(空格)
animal:
- jerry
- mario
#初始化map
score:
english:
first: 30
second: 40
third: 50
math: [131,140,148]
#初始化map{}
chinese: {first: 128,second: 136}
salarys: [3999,4999.98,5999.99]
allPets:
sick:
- {name: tom}
- {name: jerry,weight: 47}
health: [{name: mario,weight: 47}]
- 加入注释处理器(写配置文件中配置类时无任何提示,难受)
<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>