Java 在没有 Git 存储库的情况下使用 Spring Cloud Config

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33178448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:25:02  来源:igfitidea点击:

Using Spring Cloud Config without Git repo

javaspringspring-cloudspring-cloud-config

提问by Turar

Is it possible to use Spring Cloud Config without using any Git repo at all? I'm trying to test it with a local directory with this in application.properties:

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

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

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

But I get the following error:

但我收到以下错误:

java.lang.IllegalStateException: No .git at file://path/to/src/main/resources/config-repo

java.lang.IllegalStateException: 在 file://path/to/src/main/resources/config-repo 没有 .git

So is it not possible to use Spring Cloud if one is not using Git at all?

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

UPDATE:

更新:

Thanks to Spencer's advice, I added the following:

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

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

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

And I have a file "bar.properties" inside "configs" with the following contents:

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

foo: bar

But the response I get is not reading the file:

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

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

The URL I'm using is http://localhost:8888/bar/default

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

Am I missing something else? Thanks again in advance!

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

采纳答案by user1107753

You could try changing the search path to the following

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

classpath:/configs

回答by spencergibb

Run with spring.profiles.active=native. See the File System Backendfor more details. You'll want to set spring.cloud.config.server.native.searchLocationsto the dirs you want to look at.

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

回答by Horatiu

For WindowsI used it like this:

对于Windows,我是这样使用的:

spring.cloud.config.server.git.uri=C:\\Users\\my.user\\Desktop\\config\\

回答by regoug hicham

try to make your path to the directory without specifying the name of the file:

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

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

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

回答by Vikash kumar Yadav

I used the same mentioned format file:///C:/Users/home/Desktop/yourProject/git-repo and it worked for me. I am using windows system.

我使用了同样提到的格式 file:///C:/Users/home/Desktop/yourProject/git-repo 并且它对我有用。我正在使用Windows系统。

回答by Ganesh Giri

You can try this following ways:

您可以尝试以下方法:

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