首页 > 解决方案 > Spring 云服务器返回空配置

问题描述

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

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":[]}

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

标签: javaspring-bootspring-cloudspring-cloud-configspring-config

解决方案


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

更新

只是为了好玩,我用 2.2.0.BUILD-SNAPSHOT 试了一下,效果也很好。不知道此时该说什么。


推荐阅读