Spring Cloud Config - 配置中心

目录

 

配置中心 搭建

spring cloud bus

config项目中文配置


前言:

需求:实现码云git编辑配置文件,通过url刷新配置地址进行拉取到服务器,动态变更服务配置,以及配置自动刷新url

配置中心 搭建

config-server的yml

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/xxx/xxx.git
          username: xxx
          password: xxx
          default-label: master
          search-paths: /**
          basedir: F:\basedir
          force-pull: true #强制更新,可以解决 Cannot pull from remote https://******.git, the working tree is not clean.
eureka:
  client:
    service-url:
      defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/
server:
  port: 8974

 git

访问地址

http://xxx.xxx.xxx.xxx:8974/website-prod.yml

本地拉取到的文件

 备注:config的yml命名是:项目名称-prod.yml,application-prod.yml全局配置

生效说明,config服务application-prod.yml<config服务项目名称-prod.yml<项目内部bootstrap.yml配置

 

spring cloud bus

在config项目的yml中配置

management:
  endpoints:
    web:
      exposure:
        include: "*"

 访问地址

curl -X POST http://localhost:config服务端口/actuator/bus-refresh

 注意:

1如果一些配置有问题的话,最好配置在config项目内,有遇到application-prod.yml配置的rabbitmq host参数没有生效,是localhost,并不是指定ip,后来直接写在config项目的配置文件里就好了

2用的码云,配置WebHooks时,需要提供刷新的地址,直接提供可以访问的地址不行会报以下错误

{"timestamp":"2020-08-31T09:46:01.204+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token\n at [Source: (PushbackInputStream); line: 1, column: 315] (through reference chain: java.util.LinkedHashMap[\"commits\"])","path":"/actuator/bus-refresh"}

解决办法,就是提供个方法内部httppost,localhost访问的形式就行

webhooks配置的url

http://xxx.xxx.xxx.xxx:9206/bus-refresh

请求成功 ,查看了下项目访问配置信息是最新的就成功了

config项目中文配置

spring:
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值