Eureka配置中心

SpringCloud 搭建配置中心SpringCloud config

添加依赖

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- config server start -->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <!-- config server end -->

注:

  • JDK version: 1.8
  • SpringBoot version: 2.1.2.RELEASE
  • SpringCloud version: Greenwich.RELEASE

SpringCloud 版本兼容 https://spring.io/projects/spring-cloud

配置application.yml

server:
  port: 3001

spring:
  application:
    name: microservice-config-server
  # Git configuration
  cloud:
    config:
      server:
        git:
          uri: https://github.com/forezp/SpringcloudConfig/
          search-paths: respo
          default-label: master
#          uri: https://git.oschina.net/itmuch/spring-cloud-config-repo.git # Git 仓库地址
#          username:  # Git 仓库账号
#          password:  # Git 仓库密码

yml

  • spring.cloud.config.server.git.uri: 配置GitHub仓库地址(Gitee地址也可以)
  • spring.cloud.config.server.git.search-paths: 配置仓库路径
  • spring.cloud.config.label: 配置仓库的分支
  • spring.cloud.config.server.git.username: 访问GitHub仓库的用户名
  • spring.cloud.config.server.git.password: 访问GitHub仓库的用户密码

路径规则

Spring Cloud Config Server提供了RESTful API,可用来访问存在Git仓库中的配置文件.

  /{application}/{profile}[/{label}]
  /{application}-{profile}.yml
  /{label}/{application}-{profile}.yml
  /{application}-{profile}.properties
  /{label}/{application}-{profile}.properties

其中的{appliation}、{profile}、{label} 都是占位符.

  • 使用的不同配置仓库,可以更改为自己的GitHub仓库地址
  • 公开仓库不需要账号、密码,私有仓库需要填写(本Demo为公开仓库)。

测试

访问地址: http://127.0.0.1:3001/foo/dev

配套代码

TIPS

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值