spring-boot配置文件部分1-----从yml配置文件中获取属性
方式一:@Value绑定
基本类型属性注入,直接在字段上添加@Value(",而不是#.@Value注入的属性,一般其他属性没有关联关系.
@RestController
public class ConfigPropertiesController {
@Value("${simos.name}")
private String name;
@Value("${simos.age}")
private int age;
@Value("${simos.bodyWeight}")
private double bodyWeight;
@Value("${simos.girlFriend.beautiful}")
private Boolean beautiful;
@RequestMapping(value = "/config",method = RequestMethod.GET)
public String getConfigProperties(){
return "{name:"+name+",age:"+age+",beautiful:"+beautiful+",bodyWeight:"+bodyWeight+"}";
}
}
方式二:使用默认获取
默认地址resource/application.yml,从环境变量中获取。