【问题标题】:Using Spring Cloud Config without Git repo在没有 Git 存储库的情况下使用 Spring Cloud Config
【发布时间】:2016-01-15 16:14:53
【问题描述】:

是否可以在不使用任何 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": []
}

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

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

【问题讨论】:

    标签: java spring spring-cloud spring-cloud-config


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      请按照下面提到的配置进行

      这是参考

      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  
      

      #Not Working - in Windows

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

      【讨论】:

        【解决方案3】:

        您可以尝试以下方法:

        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
        

        【讨论】:

          【解决方案4】:

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

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

          【讨论】:

          • file:/// (注意 3 正斜杠,而不是原始问题中的 2 - 对我有用!)
          【解决方案5】:

          对于 Windows 我是这样使用的:

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

          【讨论】:

          • 真的吗?它仅在 config 是 git repo 并且其文件已提交时才有效。否则,配置服务器将看不到 yml/properties 文件(使用 Camden.SR5)。
          • 是的,除非该目录是 git repo,否则这是行不通的
          • 对于没有 git 的 windows;这对我有用:spring.cloud.config.server.native.searchLocations=file:/C:/toybox-config-server-repo/ (1.5.10.RELEASE)
          【解决方案6】:

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

          classpath:/configs
          

          【讨论】:

          • 目录不必在类路径中
          【解决方案7】:

          使用spring.profiles.active=native 运行。有关详细信息,请参阅File System Backend。您需要将spring.cloud.config.server.native.searchLocations 设置为您要查看的目录。

          【讨论】:

          • 对于任何使用 Windows 路径的人(可能像我一样,您正在工作站上学习 Spring Cloud 教程),我发现我需要“spring.profiles.active=native”属性以及使用这种格式的 git URI:“spring.cloud.config.server.git.uri = file:///C:/Users/MyUser/Documents/config”
          • 从头开始,这就是我需要的:“spring.profiles.active=native”和“spring.cloud.config.server.native.searchLocations=C:/Users/MyUser/Documents/config "
          猜你喜欢
          • 2020-07-23
          • 2019-01-26
          • 2013-07-21
          • 1970-01-01
          • 2021-08-13
          • 1970-01-01
          • 2016-09-09
          • 2015-02-21
          • 2021-04-25
          相关资源
          最近更新 更多