Spring Cloud Native Config Server不选择yml文件

问题描述 投票:1回答:2

我的Spring云配置服务器没有从类路径中选择yml文件

    spring:
  profiles:
    active: native
  cloud:
    config:
      server:
       native:
            search-locations: file:///C:/Users/Arun/git/MicroService_sample/config-server/src/main/resources/application-local.yml

得到低于结果,即使我使用search-locations: classpath:/configserver-local.yml,结果仍然相同

结果

  {"name":"configserver","profiles":["local"],"label":null,"version":"d1da013b1365b9001a5609e12c8590c875d782f4","state":null,"propertySources":[]}

终点:http://localhost:8080/configserver/local

并且在应用程序启动时我找不到任何用于选择yml文件的日志

java spring-cloud spring-cloud-config
2个回答
1
投票

尝试修改您的搜索位置地址

我尝试将文件放在带有.yml的D盘中,如下所示

spring:
  profiles:
    active: native
  cloud:
    config:
      server:
       native:
            search-locations: D:/

和带有内容的D:\ configserver-local.yml文件

test: 1233333

当我访问http://localhost:8080/configserver/local时,结果是预期的

{"name":"configserver","profiles":["local"],"label":null,"version":null,"state":null,"propertySources":[{"name":"file:D:/configserver-local.yml","source":{"test":1233333}}]}

1
投票

我在使用Windows上的绝对路径以纯模式设置此搜索位置时也遇到了很多麻烦。

最后,经过大量研究和尝试后,我选择将配置文件直接集成到config-server类路径中,位于src / main / resources文件夹的“config”文件夹中。

由于“本机”模式可能仅适用于开发和测试环境(对于生产,我将使用正常模式,即读取Git存储库而不是本地硬盘驱动器),对我来说这是非常好的。

您已经按照文档中的内容(因为您在Windows上,所以在“文件”之后需要3个/)。对我有用的唯一替代方法是使用user.home目录,但我不想要这个目录,所以我将属性文件放在src / main / resources / config文件夹中。

user.home目录的语法:

spring.cloud.config.server.native.searchLocations=file:///${user.home}/Downloads/config-folder
© www.soinside.com 2019 - 2024. All rights reserved.