略
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
步骤:
1、配置bootstrap.properties
spring.cloud.config.name=config
spring.cloud.config.profile=dev
spring.cloud.config.uri=http://localhost:50027
spring.cloud.config.label=master
2、配置applicatiion.properties
spring.application.name=config-client
@RestController
public class HelloController {
//获取app的版本
@Value("${app.version}")
private String version;
//获取端口号
@Value("${server.port}")
private String port;
//获取Server端参数message值
@Value("${message}")
private String message;
@GetMapping("/hello")
public String hello(){
String str="version:"+this.version+" port:"+this.port+message;
return str;
}
}
访问:http://localhost:50028/hello