Spring Cloud 配置服务器未读取本地 git 存储库中的属性文件
Posted
技术标签:
【中文标题】Spring Cloud 配置服务器未读取本地 git 存储库中的属性文件【英文标题】:Spring cloud config server is not reading the properties file in local git repository 【发布时间】:2021-03-29 00:41:03 【问题描述】:我正在尝试读取本地 git 存储库中微服务的属性文件。它没有在 propertySource 中添加文件详细信息。它是空白的。
请求 - http://localhost:8888/limit-service/default
响应 - "name":"limit-service","profiles":["default"],"label":null,"version":"91d0b396ff46642fc4efc1ec31e616487f51b10b","state":null,"propertySources":[]
本地 git 存储库中存在的属性文件的名称 - limit-service.properties
下面是配置服务器的配置细节-
spring.application.name=spring-cloud-config-server
server.port = 8888
logging.level.org.springframework = trace
spring.cloud.config.server.git.uri=file:///E:/microservice/git-local-repo
请在尝试请求详细信息时参考以下日志 -
2020-12-18 15:50:48.508 TRACE 14392 --- [nio-8888-exec-2] .b.c.c.ConfigDataEnvironmentContributors : Processing imports [file:/E:/microservice/git-local-repo/]
2020-12-18 15:50:48.508 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application.properties
2020-12-18 15:50:48.508 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application.xml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application.yml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application.yaml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service.xml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service.yml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service.yaml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application-default.properties
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application-default.xml
2020-12-18 15:50:48.509 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application-default.yml
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/application-default.yaml
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service-default.properties
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service-default.xml
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service-default.yml
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.c.ConfigDataLocationResolver : Skipping missing resource file:/E:/microservice/git-local-repo/limit-service-default.yaml
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] .b.c.c.ConfigDataEnvironmentContributors : Nothing imported
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] .b.c.c.ConfigDataEnvironmentContributors : Processed imports for of 1 contributors`enter code here`
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.config.ConfigDataEnvironment : Applying config data environment contributions
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.config.ConfigDataEnvironment : Adding imported property source 'Config resource 'file [E:\microservice\git-local-repo\limit-service.properties]' via location 'file:/E:/microservice/git-local-repo/''
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.config.ConfigDataEnvironment : Setting default profiles: [default]
2020-12-18 15:50:48.510 TRACE 14392 --- [nio-8888-exec-2] o.s.b.c.config.ConfigDataEnvironment : Setting active profiles: [default]
2020-12-18 15:50:48.510 DEBUG 14392 --- [nio-8888-exec-2] o.s.core.env.StandardEnvironment : Activating profiles [default]
2020-12-18 15:50:48.511 TRACE 14392 --- [nio-8888-exec-2] o.s.c.c.s.e.NativeEnvironmentRepository : Testing pattern: E:/microservice/git-local-repo/ with property source: E:\microservice\git-local-repo\limit-service.properties
2020-12-18 15:50:48.511 DEBUG 14392 --- [nio-8888-exec-2] o.s.c.c.s.e.NativeEnvironmentRepository : Not adding property source: E:\microservice\git-local-repo\limit-service.properties
2020-12-18 15:50:48.511 DEBUG 14392 --- [nio-8888-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json;q=0.8', given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json]
2020-12-18 15:50:48.512 TRACE 14392 --- [nio-8888-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Writing [Environment [name=limit-service, profiles=[default], label=null, propertySources=[], version=91d0b396ff46642fc4efc1ec31e616487f51b10b, state=null]]
2020-12-18 15:50:48.513 TRACE 14392 --- [nio-8888-exec-2] s.w.s.m.m.a.RequestMappingHandlerAdapter : Applying default cacheSeconds=-1
2020-12-18 15:50:48.513 TRACE 14392 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet : No view rendering, null ModelAndView returned.
2020-12-18 15:50:48.513 DEBUG 14392 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet : Completed 200 OK, headers=masked
2020-12-18 15:50:48.513 TRACE 14392 --- [nio-8888-exec-2] o.s.b.w.s.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@252c2bfc
【问题讨论】:
【参考方案1】:Spring boot 2.4.1 一定会遇到这个问题,我建议使用 Spring boot 2.3.7.RELEASE 创建新项目,它会起作用。
【讨论】:
【参考方案2】:2.4.1 版本运行良好
就我而言
我指定的路径如下 spring.cloud.config.server.git.uri=F:/me/git-localconfig-repo
【讨论】:
以上是关于Spring Cloud 配置服务器未读取本地 git 存储库中的属性文件的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot 应用程序未从 Spring Cloud Config Server 读取属性值
springCloud学习-分布式配置中心(Spring Cloud Config)
spring cloud config客户端未从配置服务器加载配置