共计 898 个字符,预计需要花费 3 分钟才能阅读完成。
1、客户端获取 ” 配置服务器 ” 放置在 Git 仓库中的配置文件
1.1、创建客户端工程
略
1.2、添加依赖
<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.3、添加配置
步骤:
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
1.4、创建用来获取配置的控制器
public class HelloController {// 获取 app 的版本 | |
private String version; | |
// 获取端口号 | |
private String port; | |
// 获取 Server 端参数 message 值 | |
private String message; | |
public String hello(){String str="version:"+this.version+"port:"+this.port+message; | |
return str; | |
} | |
} |
1.5、测试
访问:http://localhost:50028/hello
正文完
星哥玩云-微信公众号
