程序运行时,加载的指定配置目录(properties/user.properties)
@RestController
//程序运行时,加载的指定配置目录
@PropertySource(value = "classpath:/properties/user.properties",encoding="UTF-8")
public class UserController {
@Value("${user.id}")
private Integer id;
@Value("${user.username}")
private String username;
@RequestMapping("/getMsg")
public String getMsg(){
return id+ ":" + username;
}
}
程序运行时,加载的默认配置目录(application.yml)
@RestController
public class RedisController {
//spel表达式
@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private Integer port;
@GetMapping("/getNode")
public String getNode(){ //Ip:PORT
return host+":"+port;
}
}