- 創(chuàng)建一個(gè)工程(含 web ,lombok)
2 配置propertites.yml
#指定端口號(hào)
spring:
profiles:
active: dev
com.tina.username: tina
com.tina.password: 123456
- TinaConfig
@ConfigurationProperties(value = "com.tina")//可以注入在application.properties配置文件中的屬性
@Component
@Data
public class TinaConfig {
private String username;
private String password;
}
- TinaController
@RestController
@RequestMapping(value = "/tina")
public class TinaController {
@Value("${com.tina.username}")
private String username;
@Value("${com.tina.password}")
private String password;
@GetMapping(value = "/test1")
public String test1(){
return username+" "+password;
}
}
5 .啟動(dòng)類即可