美文网首页
2020-07-09---config 分布式配置中心

2020-07-09---config 分布式配置中心

作者: 李霖神谷 | 来源:发表于2020-07-09 13:47 被阅读0次

1.什么是config,为什么要使用:
随着微服务逐渐的增多,你的配置文件也会随之增多,那就带来了不好管理的问题,如果你的注册中心的端口改变了,你就需要改动很多配置文件。config通过github获取公用的配置文件。解决了这个问题。config分为客户端与服务端,客户端通过服务端拿到github上的配置信息。
2.配置服务端:

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

spring:
  application:
    name: spring-cloud-config
  cloud:
    config:
      server:
        git:
          ##git地址
          uri: https://github.com/lishuai-pro/springcloud-config.git
          ##搜索目录
          search-paths:
            - springcloud-config
##分支是哪一个
      label: master

启动类还需要配置该注解
@EnableConfigServer

3.配置客户端:

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

 cloud:
    config:
分支名称
      lable: master
文件名
      name: config
文件扩展名自动加上-
      profile: dev
服务端的地址
      uri: http://localhost:3344

4.自动化的配置,当github上的内容出现改变的时候,访问3344会发生改变,但是访问3355不会改变,必须重新启动才行。

需要添加监控的依赖:
 <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>


  ##暴露监控端点
management:
  endpoints:
    web:
      exposure:
        include: "*"


主controller上需要添加:
//git上更新之后,需要发送一个post请求即可不用启动就可以刷新改动的内容
@RefreshScope

需要通过命令行的形式刷新一下
curl -X POST "http://localhost:3355/actuator/refresh"

相关文章

网友评论

      本文标题:2020-07-09---config 分布式配置中心

      本文链接:https://www.haomeiwen.com/subject/ezhjcktx.html