Profile processor import
<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
yml file writing
Note the indentation with spaces and the spaces between key-value pairs.
person:
lastName: xiaoming
age: 18
boss: false
birth: 2020/3/20
maps: {k1: v1,k2: 12,}
lists:
- aaa
- bbb
dog:
name: buck
age: 2
JavaBean writing
Map the value of each attribute configured in the configuration file to this component
@ConfigurationProperties: Tell SpringBoot to bind all the properties in this class to the relevant configuration in the configuration file;
prefix = "person": map all attributes below in the configuration file one by one
Only this component is a component in the container, can the @ConfigurationProperties function provided by the container;
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String lastName;
private Integer age;
private Boolean boss;
private Date birth;
private Map<String,Object> maps;
private List<Object> lists;
private Dog dog;