1、配置文件声明
student:
name: 天天
age: 25
2、创建配置实体类
@ConfigurationProperties(prefix = "student")
@Component
@Data
public class ConfigPropertiesDto {
private String name;
private int age;
}
3、controller类注入配置实体类
@Autowired
private ConfigPropertiesDto configPropertiesDto;
@GetMapping("/list")
public Long list(){
System.out.println("name:"+configPropertiesDto.getName()+",age:"+configPropertiesDto.getAge());
return null;
}