【问题标题】:Spring cloud server returning empty configurationsSpring 云服务器返回空配置
【发布时间】:2019-07-21 14:07:36
【问题描述】:

我有一个简单的配置服务器,具有以下属性:

spring:
    profiles:
        active: native
    cloud:
        config:
            server:
                native:
                    searchLocations: classpath:/configs
server:
    port: 8888

在 src/main/resources 文件夹中,我有一个 configs 文件夹,其中包含一个 customer-service.yml 文件,其中包含以下配置:

spring:
    application:
        name: customer-service
    h2:
        console:
            enabled: true
server:
    port: 8080
eureka:
    client:
        serviceUrl:
            defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
    instance:
        preferIpAddress: true
        leaseRenewalIntervalInSeconds: 1
        leaseExpirationDurationInSeconds: 2
logging:
    level:
        com.netflix: WARN

配置服务器启动没有问题,但在浏览器中发出以下 URL - http://localhost:8888/customer-service/master - 返回以下响应:

{"name":"customer-service","profiles":["master"],"label":null,"version":null,"state":null,"propertySources":[]}

似乎没有很多使用类路径上的文件夹来存储配置的示例。我做错了什么?

【问题讨论】:

  • 使用 localhost:8888/customer-service/default 或仅使用 locahost:8888/customer-service 的服务器响应是什么?我从未使用过本机配置服务器,但在这种情况下标签的工作方式似乎有所不同。还有一个属性可让您删除可能有用的标签位置:spring.cloud.config.server.native.addLabelLocations=false
  • /default 给了我相同的确切响应,除了配置文件标签中的 default 和 / 给我一个 404 错误
  • 第二个参数是profile。 configs 下的列表是什么样的?
  • 我把customer-service.yml文件直接放到configs文件夹中
  • @Martin 我刚刚尝试了您的设置,但没有看到。您使用的是什么版本的 Spring Boot?我在我的 IDE 和运行 jar 中都试过了。使用 /default 或 /master 会为我返回属性源。

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


【解决方案1】:

我刚刚使用 Spring 2.1.3 进行了尝试,它可以按照您的说明工作。由于您提到您使用的是 Spring 2.2,因此可能存在更改或潜在的错误。

更新

只是为了好玩,我用 2.2.0.BUILD-SNAPSHOT 进行了尝试,它也能正常工作。不知道此时该说什么。

【讨论】:

  • 遇到了同样的问题。从 2.4.1 降级到 2.3.7 使其无需进一步更改代码或配置即可工作...
猜你喜欢
  • 2018-05-15
  • 2018-04-14
  • 2020-01-04
  • 1970-01-01
  • 2015-10-13
  • 2020-11-24
  • 2018-10-12
  • 2019-10-26
  • 2014-12-20
相关资源
最近更新 更多