阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

客户端获取配置文件

159次阅读
没有评论

共计 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、创建用来获取配置的控制器

@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; } }

1.5、测试

访问:http://localhost:50028/hello

客户端获取配置文件

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-06-06发表,共计898字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中