• 91--spring cloud (Config配置中心--客户端)


    Config客户端配置

    pom.xml 添加 config 客户端依赖

    <dependency>
    	<groupId>org.springframework.cloud</groupId>
    	<artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    

    项目中添加 bootstrap.yml

    bootstrap.yml,引导配置文件,先于 application.yml 加载

    yml的文件名称必须是bootstrap ,不可以是其他的

    具体步骤:

    1. eureka连接地址
    2. 从eureka发现配置中心
    3. 连接配置中心
    4. 下载自己的配置

    配置服务中的bootstrap.yml

    • item-service
    # 连 eureka
    eureka:
      client:
        service-url:
          defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
    # 发现配置中心(指定配置文件的serviceid)
    spring:
      cloud:
        config:
          discovery:
            enabled: true
            service-id: config-server
          name: item-service
          profile: dev
    
    
    • user-service**
    # 连 eureka
    eureka:
      client:
        service-url:
          defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
    # 发现配置中心(指定配置文件的serviceid)
    spring:
      cloud:
        config:
          discovery:
            enabled: true
            service-id: config-server
          name: user-service
          profile: dev
    
    
    • order-service
    # 连 eureka
    eureka:
      client:
        service-url:
          defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
    # 发现配置中心(指定配置文件的serviceid)
    spring:
      cloud:
        config:
          discovery:
            enabled: true
            service-id: config-server
          name: order-service
          profile: dev
    
    
    • zuul
    # 连 eureka
    eureka:
      client:
        service-url:
          defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
    # 发现配置中心(指定配置文件的serviceid)
    spring:
      cloud:
        config:
          discovery:
            enabled: true
            service-id: config-server
          name: zuul
          profile: dev
    
    

    启动服务,观察从配置中心获取配置信息的日志

    启动服务的顺序

    第一步: 启动注册中心

    第二步: 启动配置中心

    第三步:启动服务项

    注意:必须要按照顺序启动

    在服务启动过程中出现如下,则表示正常 连接端口号为6001

    image-20200904095820025

  • 相关阅读:
    nyoj 311 完全背包
    HDU 1864 最大报销额
    HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
    HDU 2602 Bone Collector
    1014 装箱问题 CODE[VS]
    JOBDU 1140 八皇后
    POJ 1979 Red and Black
    POJ 1129 Channel Allocation
    HDU 1863 畅通工程
    第二百四十七天 how can I 坚持
  • 原文地址:https://www.cnblogs.com/liqbk/p/13612531.html
Copyright © 2020-2023  润新知