//使用@Value賦值;
//1、基本數值
//2、可以寫SpEL; #{}
//3、可以寫${};取出配置文件【properties】中的值(在運行環境變量裏面的值)
@Value("張三")
private String name;
@Value("#{20-2}")
private Integer age;
@Value("${person.nickName}")
private String nickName;
在容器配置類中要寫上proprerties文件的位置
@PropertySouce
//使用@PropertySource讀取外部配置文件中的k/v保存到運行的環境變量中;加載完外部的配置文件以後使用${}取出配置文件的值
@PropertySource(value={"classpath:/person.properties"})
@Configuration
public class MainConfigOfPropertyValues {
@Bean
public Person person(){
return new Person();
}
}