【发布时间】: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