Spring Cloud git 配置——将存储库放置在直接包含类路径的文件夹中?

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

我想在应用程序的开发阶段将 git 存储库放在类路径正上方的文件夹中。

目前,我将此作为我的 Spring Cloud git URI:

spring.cloud.config.server.git.uri=file://${user.dir}/cloud-configuration-repository

此 URI 指向类路径正上方的文件夹。

但是,在运行时我收到此错误。

***************************
APPLICATION FAILED TO START
***************************

Description:

Invalid config server configuration.

Action:

If you are using the git profile, you need to set a Git URI in your configuration.  If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.

编辑:这是我希望拥有的项目结构:

Project
├── _.idea
├── src
|   ├── main
|   └── test
├── target
└── cloud-configuration-repository
java spring git cloud spring-cloud
5个回答
11
投票

来自文档:

https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html

2.1.3 文件系统后端: 配置服务器中还有一个“本机”配置文件,它不使用 Git,而是从本地类路径或文件系统加载配置文件 (您想要使用 spring.cloud.config.server.native.searchLocations 指向的任何静态 URL)。要使用本机配置文件,请使用 spring.profiles.active=native 启动配置服务器。

所以,就你而言,它将是:

spring.profiles.active=native
spring.cloud.config.server.native:searchLocations=file://${user.dir}/cloud-configuration-repository

4
投票

我遇到了与 @Nuradin 完全相同的问题,问题是我在错误的文件中添加了 spring.cloud.config.server.git.uri 属性。我需要将该行添加到 application.properties 文件而不是我的 service.properties 文件中。这是我的 application.properties 文件现在的样子:

spring.application.name=spring-cloud-config-server
server.port=8888
spring.cloud.config.server.git.uri: file://${user.home}/cloud-git-repo

我在 Windows 10 上使用 Spring Tool Suite。


3
投票

我在我的应用程序中遇到了类似的错误,以下是相同的修复方法:

a) 请在 SpringBootApplication 类中添加 @EnableConfigServer 注解

@EnableConfigServer
@SpringBootApplication
public class SpringsCloudConfigServerApplication {
--
--
}

b) 在您的 application.properties 文件中添加以下条目

spring.profiles.active=native
spring.cloud.config.server.native:searchLocations=file://ClasspathOfYourFile

spring.profiles.active=native
server.cloud.config.server.git.uri=file://ClasspathOfYourFile

2
投票

我遇到了同样的问题,我通过将

bootstrap.yml
文件重命名为
application.yml
来解决它。


0
投票

我也遇到了类似的问题,你的决定也很有效。但我希望使用 bootstrap.yml。 这个问题通过添加依赖项解决了:

implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.0.2'

添加后,我拆分了配置。 来源: 春季启动3.1.5 春云

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