Config Server:本机属性源被忽略

时间:2018-07-12 14:06:35

标签: spring spring-cloud-config

这是我的bootstrap.yml内容文件:

server.port: 8888

spring:
  application:
    name: configserver

  profiles:
    active: native, git, vault

  cloud:
    config:
      enabled: false
      server:
        native:
          searchLocations: classpath:config/
          # searchLocations: file://${native_location}
          order: 3
        git:
          uri: file:///home/jcabre/projects/wsec-sccs/server/repo
          order: 2
        vault:
          host: ${vault_server_host:localhost}
          port: ${vault_server_port:8200}
          scheme: ${vault_server_scheme:https}
          backend: ${vault_backend:configserver}
          profileSeparator: /
          order: 1

如您所见,我已经站了三个后端:本机,git,库。

所以classpath:/config/application.yml内容:

foo: FROM NATIVE APPLICATION

/home/jcabre/projects/wsec-sccs/server/repo/application.yml内容:

foo: FROM GIT

和保险柜:

$ vault kv get configserver/configclient/                        
=== Data ===
Key    Value
---    -----
foo    FROM VAULT

$vault kv get configserver/configclient/dev
=== Data ===
Key    Value
---    -----
foo    FROM DEV VAULT

当我尝试使用foo获取curl的配置密钥时:

$ curl -sS -X GET http://localhost:8888/configclient/default -H "X-Config-Token: ${vault_token}" | jq .
{
  "name": "configclient",
  "profiles": [
    "default"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "vault:configclient",
      "source": {
        "foo": "FROM VAULT"
      }
    },
    {
      "name": "file:///home/jcabre/projects/wsec-sccs/server/repo/application.yml",
      "source": {
        "foo": "FROM GIT APPLICATION"
      }
    }
  ]
}

我仅获得gitvault属性资源,但没有发送给我native

这怎么可能?

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

不知道您是否能找到答案,但是我遇到了类似的问题(启用Vault时没有本机配置文件),所以我仔细检查了代码(GitHub上的最新信息)。

似乎只有在存在本机配置文件且未配置其他环境存储库的情况下才启用NativeEnvironmentRepository。因此,看来您无法完成问题中想要做的事情。