Spring Cloud,配置服务器无法启动,如何为Git配置URI

10

我对Spring Cloud项目非常感兴趣,目前正在测试它,但遇到了阻碍。

  1. POM文件中,我添加了以下依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
  1. 主要应用程序:
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class SpringConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringConfigServerApplication.class, args);
    }
}  
根据文档,我只需要添加enableConfigServer,然后尝试启动,但是出现了以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'environmentRepository' defined in class org.springframework.cloud.config.server.ConfigServerConfiguration$GitRepositoryConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository

那么,如何为git存储库配置uri?文档中没有提到。感谢您进一步的澄清。

你可以在application.yml中提及它,作为spring.cloud.config.server.git.uri。即使我正在努力掌握这个主题,但这个资源对我帮助很大,你也应该试一试 [Spring-Cloud Sample]http://qiita.com/making@github/items/704d8e254e03c5cce546#what-is-spring-cloud-config。 - Arun
4个回答

13

我们的例子在这里。从application.yml中提取的配置如下所示:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo

2
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Aman Gupta
好的,我明白了。基本上是要在uri下设置标签,由于配置服务器已经默认打开了资源,例如/{label}/{name}-{profiles}.yml,根据文档,默认情况下标签会转到主分支。 - Aman Gupta
@spencergibb,为了添加加密/解密机制,我在类路径中添加了密钥库[*.jsk],但由于依赖项不足,无法启动应用程序。我添加了rsa依赖项,但仍然看到相同的错误。你能否发表评论,还是我需要提出新问题? - venkatReddi
任何快速帮助吗 - Caused by: org.eclipse.jgit.api.errors.RefNotFoundException: Ref master cannot be resolved? - PAA
请参见 https://github.com/spring-cloud/spring-cloud-config/issues/1722#issuecomment-832193347。 - spencergibb

4
我曾经遇到同样的问题,但当我按照下面的方式在application.yml文件中设置了配置文件时,问题就解决了:
spring:  
 profiles:   
  active: native

0

添加这个解决了问题

在yml中

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/user/microservices-central-config-repourl.git
          clone-on-start: true
          default-label: main

或者

在属性文件中

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

-4
关于这个严重的问题,你需要做的就是清理你的Maven仓库并再次更新它。这对我有用!

请在您的答案中添加更多关于解决问题的信息,以增强其内容。 - ddb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接