前两种前提开启
@ConfigurationProperties(prefix = “person”)
prefix指定配置文件对应点对象
第一种:yml配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
在这里用于配置的自动提示
person:
age: 11
last-name: 21
boss: true
birth: 1900/01/01
#map
maps:
ss: ss
sss: jjj
#list
lists:
- 2
- 3
#对象
dog:
name: 11
age: 11
值之前要有空格
第二种:properties配置
#一般变量
person.age=111
#对象
person.dog.name=1212121212
#map .key=value
person.maps.de=21212
# list 以逗号分隔
person.lists[0]=111,222,333
以下解决properties文件中文乱码(IDEA)
第三种:基于注解
//获取配置文件值
@Value("${person.dog.name}")
private String lastName;
//spring 的SpEL表达式,可运算
@Value("#{2*22}")
private Integer age;
//字面值
@Value("true")
private Boolean boss;