今天在配置Spring Cloud Config Client读取Config Server在gitee的配置文件时,出现了使用URI方式不能正常读取Config Server配置的问题。
Spring cloud版本:Greenwich.SR2
Spring Boot版本:2.1.6.RELEASE
Spring Cloud和Spring Boot版本比较多,但是它们之间有明确的对应关系,可以去查询具体的对应版本(传送门:https://spring.io/projects/spring-cloud#overview)
此问题,具体的Config Server核心配置(bootstrap.yml)如下:
cloud:
config:
server:
git:
uri: https://gitee.com/username/springcloud-config-server
username:
password:
search-paths: config-files
default-label: master
此配置,经过测试没有发现问题,Config Server可以正常同步在gitee上的配置文件。
Config Client的核心配置部分(bootstrap.yml)如下:
spring:
cloud:
config:
name: config-client
label: master
profile: dev
uri: http://localhost:7002
上面文件采用URI的同步访问方式,启动后控制台没有打印出fetching config from server http://localhost:7002等的提示信息,很明显是Config Client访问Config Server出现的问题,中间尝试过很多网上搜索的方法,包括bootstrap从yml换成properties;更换配置文件从yml到properties等等均没有解决。尝试换一种配置方式,通过查找eureka注册中心的Config Server的Application name,配置如下:
spring:
application:
name: config-client
cloud:
config:
discovery:
enabled: true
service-id: config-server #config server的注册application name
profile: dev
label: master
如下图,久违的fetching信息出现,问题解决。至于为什么使用URI不能访问,暂时还没有找到原因。