application.yml文件定义
ttt:
name: kkk
age: 18
1.使用@Value注入
@Component
public class Tests {
@Value("${ttt.name}")
private static String name;
@Value("${ttt.age}")
private static Integer age;
}
2.使用@ConfigurationProperties(prefix = " ")注入
@Component
@ConfigurationProperties(prefix = "ttt")
public class Tests {
private static String name;
private static Integer age;
}