在使用配置中心拉取配置文件的时候,有时候总会遇到很多让人很郁闷的问题,如果本地缓存文件被更改的时候就会遇到以下问题:
Cannot pull from remote https://git.zhubanxian.com/zhu/online_edu_config.git, the working tree is not clean.
而我遇到这个问题的原因就是因为吧本地的缓存给删了。
其实在Spring Cloud官网给出了答案
https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#force-pull-in-git-repositories
Spring Cloud配置服务器会复制远程git存储库,如果本地副本变得不干净(例如,通过OS进程更改文件夹内容),那么Spring Cloud配置服务器就不能更新远程存储库中的本地副本。为了解决这个问题,有一个强制拉属性,如果本地副本是脏的,它将使Spring Cloud配置服务器从远程存储库中强制pull.
spring:
application:
name: public-config
cloud:
config:
server:
git:
uri: https://git.zhubanxian.com/zhu/online_edu_config.git
username: ***
password: ***
basedir: C:/work/config/tmp
force-pull: true
添加 force-pull 属性 默认是false
同时在重新启动Config server的时候需要删除原来临时的配置文件