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

实现配置中心和配置客户端的服务化

144次阅读
没有评论

共计 1145 个字符,预计需要花费 3 分钟才能阅读完成。

1、实现配置中心和配置客户端的服务化

1.1、实现服务器端服务化

1.1.1、添加依赖

<!--eureka 依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>

1.1.2、添加配置

在 bootstrap.propertes 中添加

eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
eureka.client.service-url.defaultZone=http://eureka01:50025/eureka/,http://eureka02:50026//eureka/
#开启 Config Server 使用服务发现的功能
spring.cloud.config.discovery.enabled=true

1.1.3、添加服务中心支持

在启动类中,添加注解 @EnableDiscoveryClient

1.2、实现客户端服务化支持

1.2.1、添加依赖

<!--eureka 依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>

1.2.2、添加配置

在 bootstrap.properties 中添加

spring.cloud.config.name=config
spring.cloud.config.profile=dev
spring.cloud.config.uri=http://localhost:50027
spring.cloud.config.label=master
#启用 Bus 支持
spring.cloud.bus.enabled=true
#启用 Bus 的跟踪支持
spring.cloud.bus.trace.enabled=true
#开启 Config Server 使用服务发现的功能
spring.cloud.config.discovery.enabled=true
#必须配置
spring.cloud.config.fail-fast=true
spring.cloud.config.discovery.service-id=config-server

1.2.3、添加 ” 服务中心 ” 支持

在启动类中添加注解 @EnableDiscoveryClient

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