Método 1: anotación @value
school:
name: shcool1
student:
zyk: zyk
@RestController
public class Demo1Controller {
@Value("${school.student.zyk}")
public String name;
@RequestMapping("/hello")
public String getName() {
return name;
}
}
Método 2:
Use la anotación @configurationproperites
Lo que quiero obtener es school.name y school.student
@configurationproperites + nombre de variable de clase, puede obtener atributos yaml de varios niveles
school:
name: school1
student: zyk
@Data
@ConfigurationProperties("school")
@Component
public class Demo2pro {
private String name;
private String student;
}
@RestController
public class Demo2Controller {
@Autowired
Demo2pro demo2pro;
@RequestMapping("/hello2")
public String getName() {
return demo2pro.getName()+demo2pro.getStudent();
}
}