springcloud-config基本构建-配置中心

        Spring Cloud Config为所有微服务提供一个统一的外部配置的地方。

       可以将Spring Cloud Config理解成一个微服务ConfigServce,也是要注册到注册中心euraka中,同时他要与github整合,将配置文件存放到github中,ConfigServce到GitHubs进行拉取,而其他的微服务端到ConfigService上进行获取配置。【ConfigServce也可以用本地作为配置文件的存储仓库,即本项目的property文件】

        接下来是怎么配置出这个ConfigServce服务

1、pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

2、application.yml【一个配置是和git适配的配置、一个是注册到euraka的配置】

server:
  port: 3344
spring:
  application:
    name: config-center
  cloud:
    config:
      server:
        git:
          #仓库地址
          uri: https://github.com/xzjyy/springcloud-config.git
          search-paths:
            - springcloud-config  #要扫描的文件
          username: xzjyy #github的用户名
          #gitHub的令牌
          password: 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
      label: master #分支

eureka:
  client:
    #表示是否将自己注册进EurekaServer默认为true
    register-with-eureka: true
    #是否从EurekaServer抓取已有的注册信息,默认为true。
    #单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/

3、启动类上增加一个配置中心服务的注解   

@EnableConfigServer

4、启动服务,可以用get的请求方式,请求对应配置文件

http://{configService.IP}:{port}http://{configService.IP}:

5、其他服务端增加一个BootStrap.yml文件-读取配置中心信息的配置文件

server:
  port: 3355
spring:
  application:
    name: config-client
  cloud:
    config:
      #分支名称
      label: master
      name: config  #配置文件名称
      profile: dev  #读取后缀名称
      uri: http://localhost:3344 #配置中心地址k
      #上述3个综合:master分支上config-dev.yml的配置文件被读取
      #http://config-3344.com:3344/master/config-dev.yml
eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值