为什么需要配置中心?
不方便维护
配置内容的安全和配置
更新项目配置需要重启

springcloud(5)config server
springcloud(5)config server

由于config-server 既是eureka的client端,又是config的server端。

springcloud(5)config server

然后我们选用的是https://gitee.com/XXXXXX/order.yml
新建order.yml
springcloud(5)config server

然后配置文件 application.yml

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/xxxxxxx/config-repo.git
          username: [email protected]
          password: xxxxxx
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

记住这里是spring.cloud.config.git.uri

然后访问http://localhost:8080/order-a.yml
然后就能访问到:
springcloud(5)config server

springcloud(5)config server
http://localhost:8080/order-a.properties

springcloud(5)config server
http://localhost:8080/order-a.json

配置命名的约定规则:
如:
1./order-dev.yml (/文件名-环境名.文件后缀)
2./dev/order-dev.yml (/分支名/文件名-环境名.文件后缀)
每一种都可以用
/{name}-{profiles}.yml
/{label}/{name}-{profiles}.yml
name 服务名
profile 环境
label 分支 branch

其实springcloud config会把远端的git拉到本地的git上来。
springcloud(5)config server

然后可用指定 basedir;再新建个文件夹,不然会被清空:

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/xxxxx/config-repo.git
          username: [email protected]
          password: xxxx
          basedir: /Users/xxx/xxxxx/xxx-springcloud-xx/config/basedir
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka

相关文章:

  • 2022-01-07
  • 2021-12-26
  • 2021-08-15
  • 2021-10-11
猜你喜欢
  • 2021-06-29
  • 2021-07-18
  • 2022-12-23
  • 2021-07-22
  • 2021-05-09
  • 2022-12-23
相关资源
相似解决方案