springboot配置文件绑定类


1.yml文件绑定类

dog:
  name: wangshenzhen
  age: 18

2.在类上添加注解

@ConfigurationProperties(prefix = "dog")

1.properties文件wang.properties绑定类

name=wangshenzhen

2.在类上添加注解

@PropertySource(value = "classpath:wang.properties")
public class Dog {
    @Value("${name}")
    private String name;
    private Integer age;
}