40

是否可以在不使用任何 Git 存储库的情况下使用 Spring Cloud Config?我正在尝试在 application.properties 中使用本地目录对其进行测试:

spring.cloud.config.server.git.uri=file://${user.dir}/src/main/resources/config-repo

但我收到以下错误:

java.lang.IllegalStateException:文件中没有 .git://path/to/src/main/resources/config-repo

那么,如果一个人根本不使用 Git,就不可能使用 Spring Cloud 吗?

更新:

感谢 Spencer 的建议,我添加了以下内容:

spring.profiles.active=native spring.cloud.config.server.native.searchLocations=${user.dir}/src/main/resources/configs

我在“configs”中有一个文件“bar.properties”,内容如下:

foo: bar

但是我得到的响应不是读取文件:

{
  "name": "bar",
  "profiles": [
    "default"
  ],
  "label": "master",
  "propertySources": []
}

我使用的 URL 是http://localhost:8888/bar/default

我还缺少其他东西吗?再次提前感谢!

4

7 回答 7

36

运行spring.profiles.active=native。有关更多详细信息,请参阅文件系统后端。您需要设置spring.cloud.config.server.native.searchLocations为要查看的目录。

于 2015-10-16T20:32:52.747 回答
18

您可以尝试将搜索路径更改为以下

classpath:/configs
于 2015-10-19T15:05:28.547 回答
14

对于Windows,我这样使用它:

spring.cloud.config.server.git.uri=C:\\\\Users\\\\my.user\\\\Desktop\\\\config\\\\
于 2016-12-22T07:10:46.307 回答
2

尝试在不指定文件名的情况下创建目录路径:

file:///C:/Users/home/Desktop/yourProject/git-repo

于 2018-05-23T18:20:36.980 回答
1

您可以尝试以下方法:

file:\\C:/WORKSPACE/GIT/repo
file:///C:/microservices/repo
file:///C:/Users/test/Documents/workspace-sts-3.9.4.RELEASE/repo
file:\\C:/Users/test/Documents/workspace-sts-3.9.4.RELEASE/repo
于 2020-03-02T16:58:35.850 回答
1

请按照下面提到的配置

这是参考

https://cloud.spring.io/spring-cloud-config/reference/html/#_spring_cloud_config_server

# 工作 - 在 Windows 中

spring.cloud.config.server.git.uri=file:/C:/git-repo 

spring.cloud.config.server.git.uri=file:///C:/git-repo 

spring.cloud.config.server.git.uri=C:\\\\git-repo  

#不工作 - 在 Windows 中

#spring.cloud.config.server.git.uri=file:///C:\git-repo 
于 2021-02-22T03:02:13.763 回答
0

这适用于Windows(我在 /Desktop 中创建了一个配置文件夹):

spring.cloud.config.server.git.uri=file:///${user.home}/Desktop/config

以下不起作用,所以我在上面使用:

spring.cloud.config.server.git.uri=file://${HOME}/Desktop/config
于 2021-04-13T15:42:43.490 回答