spring 配置服务器 - 用于本地 git 存储库

问题描述 投票:0回答:7

我正在尝试设置 Spring Cloud 配置服务器

-在我的本地创建了 git 存储库文件夹 F:\git 本地存储库 储存库

-使用类路径链接源链接它 -为我的服务添加了属性文件

-在位置 F:\git-local-repository 提交更改后 储存库

-点击网址:http://localhost:8888/limits/default

导致错误: org.springframework.cloud.config.server.environment.NoSuchLabelException:没有这样的标签:master

原因:org.eclipse.jgit.api.errors.RefNotFoundException:Ref master 无法解析

以下是我的 Spring Boot 应用程序的主类

@EnableConfigServer


@SpringBootApplication
public class SpringCloudConfigServerApplication {

public static void main(String[] args) {
    SpringApplication.run(SpringCloudConfigServerApplication.class, args);


}

}

application.properties

spring.application.name=spring-cloud-config-server

server.port=8888

spring.cloud.config.server.git.uri=file:////F:/git-local- 
repository/repository

预期结果:将显示应用程序属性详细信息和其他 url

java spring git microservices spring-boot-2
7个回答
3
投票

如果您使用本地目录进行配置。

而不是

spring.cloud.config.server.git.uri=file:////F:/git-local-repository/repository

使用

spring.cloud.config.server.native.search-locations=file:////F:/git-local-repository/repository

2
投票

问题在于额外的正斜杠。 请改成这样:

spring.cloud.config.server.git.uri=file:///F:/git-local- 
repository/repository

1
投票

我也遇到了同样的问题,这是因为 git 更改了分支的默认名称,现在是 main,而 spring 正在搜索 master。

添加 'spring.cloud.config.server.git.default-label=main' 解决了我的问题。


0
投票

如果您发出NoSuchLabelException,您可以尝试添加 spring.cloud.config.server.git.default-label=branch-name 属性,以将您的 Spring Cloud 配置服务器直接引导到此分支。


0
投票

我在几个小时内遇到了完全相同的问题 你必须使用

第一件事 在 SpringCloudConfigServer 的 application.properties 中使用它

spring.profiles.active=native

spring.cloud.config.server.native.search-locations=file:////F:/git-local-repository/repository

而不是

spring.cloud.config.server.git.uri
,因为 Spring 版本发生了变化

第二件事 就是让你的本地 git 作为 Intellij 上的 ''源根''

    选择您的 LocalGitRepo 包
  1. 右键单击 -> 将目录标记为 -> 标记为源根目录
这将使 Spring 读取 local-git 中的 microservice.properties,将 /microservice.properties 添加到位置路径不会有帮助


-1
投票
使用以下配置添加 bootstrap.yml 文件对我有用。

spring: application: name: spring-cloud-config-server profiles: active: composite cloud: config: server: composite: - type: native search-locations: file:////F:/git-local-repository/repository bootstrap: true server: port: 8888 endpoints: restart: enabled: true
    

-1
投票
做了很多事情来解决这个问题,但它正在添加

spring.cloud.config.server.git.default-label=main 到 application.properties 有效

© www.soinside.com 2019 - 2024. All rights reserved.