目录
前言:
需求:实现码云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