mst*_*tzn 4 spring-boot spring-cloud-netflix spring-cloud-config
我有一个简单的 Spring Cloud Config Server,它使用来自 git 服务器的配置。
ConfigServer bootstrap.yml :
spring:
application:
name: config-service
cloud:
config:
server:
git:
uri: ssh://git@mydomain:myport/myrepo.git
searchPaths: "configurations/{application}/{profile}"
server:
port: 8888
Run Code Online (Sandbox Code Playgroud)
当我在本地部署 ConfigServer 时,我可以从http://localhost:8888/myapp/test. 但是当我在测试服务器上部署 ConfigServer 时,No such label: master当我点击http://testserverip:8888/myapp/test.
非常感激任何的帮助!
小智 21
我知道我很晚才发布这个答案。但是,仍然发布它,以便其他人可以发现这有帮助。现在,GitHub 的默认分支名称是“main”,但 Spring Cloud Config 仍然寻找“master”作为标签名称。因此,如果您想更改默认行为,您始终可以使用以下属性更改标签名称查找application.yml或application.properties:
spring.cloud.config.server.git.default-label=main
Run Code Online (Sandbox Code Playgroud)
这对我来说非常有效。我正在使用 Spring Boot 2.3.6.RELEASE
GitHub 创建了默认分支“main”,但是 Spring cloud Config 正在寻找“master 分支”。我创建了一个“master”分支并且它成功了!
我也面临着同样令人烦恼的情况。
\n\n我将首先说明我如何解决这个场景,然后强调我在之前的方法中犯的错误。\n在我的上下文中,我正在使用application.properties
我的应用程序概述如下所示:\n我有一个集中的配置服务器,并向各个微服务提供相应的配置数据。
\n\n例如,一个微服务“limits-service”需要一些配置数据,它从中央配置服务器(“spring-cloud-config-server”)获取它。\n因此要实现这一点,\' limit-service\' 查询中央配置服务器,该服务器又从远程 git 分支(\'spring-cloud-samples\')获取请求的数据。
\n\n \xe2\x94\x8c---------------------- <--> [currency-exchange-service]\n [git] <--> [spring-cloud-config-server] ------- <--> [limits-service] \n \xe2\x94\x94---------------------- <--> [currency-conversion-service]\nRun Code Online (Sandbox Code Playgroud)\n\n我只是为所有配置文件创建了一个新的 Git 存储库 (spring-cloud-samples),这些配置文件将通过中央配置服务器由多个微服务使用。
\n\n在application.properties中央配置服务器(\'spring-cloud-config-server\')的文件中,我提供了一个属性:
spring.cloud.config.server.git.uri=https://github.com/{username}/{git-reponame.git}\nRun Code Online (Sandbox Code Playgroud)\n\n这可能看起来像
\n\nspring.cloud.config.server.git.uri= https://github.com/alice123/spring-cloud-samples.git \n就是这样!
\n\n启动我的中央配置服务器并观察日志,如下所示:
\n\n2020-02-17 05:25:07.867 INFO 15000 --- [nio-8888-exec-9] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/D:/Users/{userName}/AppData/Local/Temp/config-repo-3453413414/limits-service.properties\nRun Code Online (Sandbox Code Playgroud)\n\n此外,我还通过我的“限制服务”消耗了配置数据,它的作用就像一个魅力!
\n\n我尝试了以下方法,但结果都失败了,还引发了很多尖叫和大喊大叫。XD
\n\n我发布它,只是为了让尝试同样概念的人可以节省一晚上的工作,或者可能更少:p
\n\n1)最初,我在central-config-server的application.properties文件中使用我的Git存储库SSH URL,如下所示:
\n\nspring.cloud.config.server.git.uri=git@github.com:alice123/spring-cloud-samples.git\nspring.cloud.config.server.git.username=alice123\nspring.cloud.config.server.git.password=alice123Pwd\nRun Code Online (Sandbox Code Playgroud)\n\n这导致了以下错误:
\n\n2020-02-17 05:22:45.091 WARN 15000 --- [nio-8888-exec-1] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.\norg.eclipse.jgit.api.errors.TransportException: git@github.com:aniketrb-github/spring-cloud-samples.git: Auth fail\nRun Code Online (Sandbox Code Playgroud)\n\n2)后来,我尝试从本机/本地 git 目录读取配置数据,该目录指向我的 Git 远程分支(spring-cloud-samples)\n然后我在 application.properties 文件中提供了以下内容:
\n\nspring.cloud.config.server.git.uri=file://D:\\aniket-workspace\\github-ws\\microservices\\udemy-microservices\\git-localconfig-repo\nRun Code Online (Sandbox Code Playgroud)\n\n这崩溃了:
\n\njava.lang.IllegalStateException: Failed to load property source from location \'classpath:/application.properties\'\nRun Code Online (Sandbox Code Playgroud)\n\n3)后来经过足够的谷歌搜索后,我将上述属性更改为以下有效!!:
\n\nspring.cloud.config.server.git.uri=D:\\\\\\\\alice-workspace\\\\\\\\github-ws\\\\\\\\microservices\\\\\\\\git-localconfig-repo\nRun Code Online (Sandbox Code Playgroud)\n\n“limits-service”最终在尝试从“spring.cloud.config.server”获取配置数据时失败,并出现以下错误:
\n\n404: Not Found - "org.springframework.cloud.config.server.environment.NoSuchLabelException: No such label: master"\nRun Code Online (Sandbox Code Playgroud)\n\n由于我遇到了上面提到的所有失败,我所说的解决方案对我有用。\n如果我错了,请纠正我,并在必要时即兴发挥。我希望这会有所帮助并节省一些关键时间。
\n\n参考文献:spring-cloud-config、https-or-ssh、git-ssh-windows、git-ssh-windows-troubleshooting
\n就我而言,给出的答案都不起作用。唯一有效的是将 default-label 设置为 master
spring.cloud.config.server.git.default-label=master
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10256 次 |
| 最近记录: |