简体   繁体   English

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

[英]Using Spring Cloud Config without Git repo

Is it possible to use Spring Cloud Config without using any Git repo at all?是否可以在不使用任何 Git 存储库的情况下使用 Spring Cloud Config? I'm trying to test it with a local directory with this in application.properties:我正在尝试使用 application.properties 中的本地目录对其进行测试:

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

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!再次提前致谢!

Run with spring.profiles.active=native .使用spring.profiles.active=native运行。 See the File System Backend for more details.有关更多详细信息,请参阅文件系统后端 You'll want to set spring.cloud.config.server.native.searchLocations to the dirs you want to look at.您需要将spring.cloud.config.server.native.searchLocations设置为您想要查看的目录。

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

classpath:/configs

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

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

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

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

Please follow the below mentioned configurations请按照下面提到的配置

Here is the Reference这是参考

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

# Working - in Windows # 工作 - 在 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  

#Not Working - in Windows #不工作 - 在 Windows 中

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

I used the same mentioned format file:///C:/Users/home/Desktop/yourProject/git-repo and it worked for me. 我使用了相同的格式文件:/// C:/ Users / home / Desktop / yourProject / git-repo,它对我有用。 I am using windows system. 我正在使用Windows系统。

This worked for Windows (I created a config folder in /Desktop):这适用于Windows (我在 /Desktop 中创建了一个 config 文件夹):

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

The following didn't work so I used above:以下不起作用,所以我在上面使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM