springcloud config(分布式配置中心)

1 添加依赖

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

2 添加配置

server:
  port: 12000
eureka:
  client:
    service-url:
      defaultZone: http://admin:1234@localhost:7001/eureka/
    fetch-registry: true
    register-with-eureka: true

spring:
  application:
    name: hello-config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/dp147258/hello-sc-2109a.git
          search-paths: /**/config
      label: master
  zipkin:
    base-url: http://192.168.0.114:9411/

3.添加启动类

@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer

4.在provider(服务提供者添加依赖)

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

5.在provider(服务提供者)创建bootstrap.yml配置文件 删除appplication.yml里面配置(保留info跟logging日志)

bootstrap

server:
  port: 9999

spring:
  application:
    name: hello-provider
  jackson:
    date-format: yyyy-MM-dd
    time-zone: GMT+8

  cloud:
    config:
      discovery:
        enabled: true  #开启配置服务发现
        service-id: hello-config #配置中心服务名称
      label: master  #分支名称
      profile: dev #环境名称
eureka:
  client:
    service-url:
      defaultZone: http://admin:1234@localhost:7001/eureka/,http://admin:1234@localhost:7002/eureka/
    register-with-eureka: true
    fetch-registry: false
  instance:
    instance-id: ${spring.application.name}-${server.port}
    prefer-ip-address: true
    status-page-url-path: /actuator/info
    health-check-url-path: /actuator/health

5.创建目录(方便区分)跟项目同名 gitBatch

创建文件夹config定义两个.yml文件(因在bootstrap跟application里面已无数据源)

在刚定义的.yml文件里面配置数据源

spring:
  datasource:
    username: root
    password: 1234
    url: jdbc:mysql:///db2109

创建文件 (方便上传)

在码云里面创建添加仓库(跟项目同名) ->开源

git init 初始化

git add . 添加暂存区

git commint . -m """" 提交到版本库

执行码云里面最后两行代码

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值