第三章:SpringCloud将config server and client 注册至 eureka

1.将config server注册至eureka

  • pom不变
  • 启动类添加注解@EnableDiscoveryClient(不用引入eurekaclient,因为得导入依赖)
  • application
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/jiaofanting/spring-cloud-config-repo/
  application:
    name: config-server-eureka
server:
  port: 8080
eureka:
  client:
    service-url:
      defaultZone:  http://127.0.0.1:9000/eureka

可以说就是正常注册

2.将config client注册至eureka

  • pom不变
  • 启动类加注解@EnableDiscoveryClient(需要引入eureka client依赖)
  • bootstrap
spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server-eureka
  application:
    name: config-client-eureka
eureka:
  client:
    service-url:
      defaultZone:  http://127.0.0.1:9000/eureka

application只设置了端口,这里我就不贴代码了
这段配置有个重点就是

spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server-eureka

连接config server方法变了。我们来看看这个enabled是什么

img_b6ebc5384925125c8bdba30ccfa967cf.png
image.png

Flag to indicate that config server discovery is enabled (config server URL will be looked up via discovery).

意思是 enabled这个标记表明server 服务发现是开启的(server url将被发现)
意思就是 会从eureka发现列表里找到config server 的url

img_08ab3aeb29673093e26bb7028debe9be.png
image.png

访问config client 的controller 的 /profile方法
img_e5d33a3bdf225155b7d9aac205c977b0.png
image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值