繁体   English   中英

从Spring Cloud Config Server获取配置时,Spring配置文件无法正确排序

[英]Spring profiles not ordering correctly when obtaining config from Spring Cloud Config Server

我有一个Spring Boot应用程序,它从Spring Cloud配置服务器(本机模式)获取配置。 配置服务器加载的配置位置中的基本application.yml文件包含以下内容:

eureka:
  client:
    service-url:
      defaultZone: ${BOOT_EUREKA_LOCATIONS:http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka}
  register-with-eureka: true
---
spring:
  profiles: test
eureka:
  client:
    register-with-eureka: false #no registration on Eureka when testing
    service-url:
      defaultZone: ${BOOT_EUREKA_LOCATIONS:http://sparky:8761/eureka}

当击中配置服务器的端点( http:// mygateway / config-server / myapp / test )时,我将在配置文件“ test”中运行的“ myapp”应用程序返回以下信息:

{
"name": "myapp",
"profiles": [
    "test"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
    {
        "name": "file:////wherever/application.yml#test",
        "source": {
            "spring.profiles": "test",
            "eureka.client.register-with-eureka": false,
            "eureka.client.service-url.defaultZone": "${BOOT_EUREKA_LOCATIONS:http://sparky:8761/eureka}"
        }
    },
    {
        "name": "file:////whereever/application.yml",
        "source": {
            "eureka.client.service-url.defaultZone": "${BOOT_EUREKA_LOCATIONS:http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka}"

在测试配置文件中运行myApp时,eureka.client.service-url.defaultZone的值为http://instance1.localhost:7761 / eureka,http://instance2.localhost:7762 / eureka,http:// instance3 .localhost:7763 / eureka ,这是意外的。

我希望测试配置文件中的条目将其覆盖(如果您在本地拥有application.yml,它也会这样做)。 关于为什么在myApp中使用值时为什么不能从“测试”配置文件中获取值的想法?

我的意图是在顶部添加“默认”值,并让“配置文件”覆盖所有非标准默认值。

更新:myApp / env不显示已加载的“ application.yml#test”,但是显示测试配置文件,但仅显示从配置服务器返回的默认值(而不是#test):

{
  "profiles": [
    "test"
  ],
  "server.ports": {
    "local.server.port": 7761
  },
  "configService:file:////wherever/application.yml": {
    "eureka.client.service-url.defaultZone": "http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka"

这是一个完整的用户错误。 我在application.yml中设置了默认的“测试”活动配置文件,而不是将其作为环境变量或bootstrap.yml传入,因此尚未足够快地加载该配置服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM