8

我有一个简单的 Spring Cloud Config Server,它使用来自 git 服务器的配置。

配置服务器 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

当我在本地部署 ConfigServer 时,我可以从http://localhost:8888/myapp/test. 但是当我在测试服务器上部署 ConfigServer 时,它会No such label: master在我点击http://testserverip:8888/myapp/test.

非常感激任何的帮助!

在此处输入图像描述

4

10 回答 10

33

我知道我很晚才发布这个答案。但是,仍然发布它,以便其他人可以发现这很有帮助。现在,GitHub 的默认分支名称是“main”,但 Spring Cloud Config 仍然寻找“master”作为标签名称。因此,如果您想更改默认行为,您始终可以使用以下属性更改标签名称查找application.ymlapplication.properties

spring.cloud.config.server.git.default-label=main

这对我来说效果很好。我正在使用 Spring Boot 2.3.6.RELEASE

于 2020-12-10T05:10:36.987 回答
4

GitHub 创建了默认分支“main”,但是 Spring cloud Config 正在寻找“master 分支”。我创建了一个“主”分支并且它有效!

于 2020-10-14T11:16:08.110 回答
3

当您的服务无法访问 Git 存储库时会发生这种情况。由于您可以启动您的应用程序,我假设测试服务器可以访问 Git。您应该为您的 Git 服务器设置 SSH 身份验证。您可以查看此站点的 SSH 配置。

于 2016-10-14T19:36:50.043 回答
3

我遇到了同样令人讨厌的情况。

我将首先说明我是如何解决这种情况的,然后会强调我在以前的方法中所犯的错误。在我的上下文中,我正在使用application.properties

我的应用程序概述如下所示:我有一个集中的配置服务器并将相应的配置数据提供给相应的微服务。

例如,一个微服务“limits-service”需要一些配置数据,它从中央配置服务器(“spring-cloud-config-server”)获取。因此,为了实现这一点,“limits-service”查询中央配置服务器,该服务器又从远程 git 分支(“spring-cloud-samples”)获取请求的数据。

                            ┌---------------------- <--> [currency-exchange-service]
    [git] <--> [spring-cloud-config-server] ------- <--> [limits-service] 
                            └---------------------- <--> [currency-conversion-service]

解决方案:

我只是为所有配置文件创建了一个新的 Git 存储库(spring-cloud-samples),这些配置文件将由多个微服务通过中央配置服务器使用。

application.properties中央配置服务器('spring-cloud-config-server')的文件中,我提供了一个属性:

spring.cloud.config.server.git.uri=https://github.com/{username}/{git-reponame.git}

这可能看起来像

spring.cloud.config.server.git.uri= https://github.com/alice123/spring-cloud-samples.git 就是这样!

在启动我的中央配置服务器并观察日志如下:

2020-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

此外,我还通过我的“限制服务”消耗了配置数据,它就像一个魅力!

我尝试了以下导致失败和大量尖叫和大喊大叫的事情。XD

我发布它,只是为了让尝试相同概念的人可以节省一个晚上的工作,或者更少:p

1)最初,我在 central-config-server 的 application.properties 文件中使用我的 Git Repositories SSH URL,如下所示:

spring.cloud.config.server.git.uri=git@github.com:alice123/spring-cloud-samples.git
spring.cloud.config.server.git.username=alice123
spring.cloud.config.server.git.password=alice123Pwd

这导致了以下错误:

2020-02-17 05:22:45.091  WARN 15000 --- [nio-8888-exec-1] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: git@github.com:aniketrb-github/spring-cloud-samples.git: Auth fail

2)后来,我尝试从本机/本地 git 目录中读取配置数据,该目录指向我的 Git 远程分支(spring-cloud-samples)然后我在我的 application.properties 文件中提供了以下内容:

spring.cloud.config.server.git.uri=file://D:\aniket-workspace\github-ws\microservices\udemy-microservices\git-localconfig-repo

这崩溃了:

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.properties'

3)后来经过足够的谷歌搜索,我将上面的属性更改为下面的工作!!:

spring.cloud.config.server.git.uri=D:\\\\alice-workspace\\\\github-ws\\\\microservices\\\\git-localconfig-repo

'limits-service' 在尝试从'spring.cloud.config.server' 获取配置数据时最终失败,并出现以下错误:

404: Not Found - "org.springframework.cloud.config.server.environment.NoSuchLabelException: No such label: master"

由于我上面提到的所有失败,我所说的解决方案对我有用。如果我错了,请纠正我并在必要时即兴创作。我希望这会有所帮助并节省一些关键时间。

参考:spring-cloud-confighttps-or-sshgit-ssh-windowsgit-ssh-windows-troubleshooting

于 2020-02-17T02:04:29.010 回答
1

当您创建一个新的存储库时,现在的 git 将“main”作为默认分支而不是 master。这个问题就是关于这个的。

手动创建“master”分支。它将解决所有这些问题。

于 2020-10-28T15:36:16.730 回答
1

对我来说,这是由于我的默认分支“main”引起的。每当您创建新分支时,默认分支不再是“主”而不是“主”。但是 spring server config 寻找 master 分支。快速的解决方案是从“主”分支签出一个名为“主”的新分支。并从 spring 配置服务器尝试。而已。

从主分支创建一个新分支。首先指向主分支并从那里

git checkout -b master git push --set-upstream origin master

重新启动配置服务器并测试

于 2020-10-30T15:00:18.317 回答
0


我希望你做得很好。
我正在使用 STS 4 并添加了源链接文件夹(本地 git 存储库),用于从本地 git 存储库进行 spring 云配置。
我遇到了同样的问题,
我只是用正斜杠改变了反斜杠。
当我这样使用时

spring.cloud.config.server.git.uri=file://C:\Users\coder\Desktop\spring material\in28microservies\git-localconfig-repo

我有错误

2020-04-04 14:57:37.874 ERROR 6952 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot load environment] with root cause
java.lang.IllegalStateException: Cannot convert uri to file: file://C:UserscoderDesktopspring materialin28microserviesgit-localconfig-repo

然后我只是在配置服务器属性文件中用正斜杠替换了所有反斜杠,
它对我有用

spring.cloud.config.server.git.uri=file://C:/Users/coder/Desktop/spring material/in28microservies/git-localconfig-repo
于 2020-04-04T10:10:24.443 回答
0

这肯定会工作!:)

1)如果您在该特定文件夹中首次初始化存储库,则必须以下列方式提交更改以显示主控

> git add -A .
> git commit -m "added prop..."

2)重新运行项目并点击相同的网址。

恩乔伊:)

于 2020-07-21T10:42:08.930 回答
0
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file://<location>

试试下面我们朋友提到的这个:

https://stackoverflow.com/a/33179106/1908827

于 2020-08-23T22:14:40.047 回答
0

这也是我在遇到类似问题时发现的。

问题/错误#1 >> 我使用记事本创建了属性文件(我在 Windows 操作系统上)。该文件是使用 .txt 扩展名创建的。因此,云配置没有接受更改。修复:将扩展名从 .txt 更改为 .properties

问题/错误#2 >> .properties 文件名与提到的不同。该文件应命名为:

服务名.properties

  matching the servicename defined in the *application.properties* as below:

spring.application.name=<<服务>>

在我的例子中:

 spring.application.name=limits-service

因此文件应该被命名**limits-service.properties**,但我用这个名字创建limits-service-service.properties

enter code here

修复:将文件重命名为:limits-service.properties

现在我可以看到 spring-cloud-config 中的配置,它正在从配置的 GIT 存储库中选择值。

于 2022-02-11T08:49:51.163 回答