Spring Cloud无法将Vault秘密解析为.yml

时间:2020-04-09 14:22:23

标签: spring spring-boot spring-cloud hashicorp-vault spring-vault

我正在使用微服务架构,并具有spring cloud config服务和另一个微服务。

  profiles:
    active: vault
  cloud:
    # Configuration for a vault server running in dev mode
    vault:
      scheme: http
      host: 127.0.0.1
      port: 8200
      connection-timeout: 5000
      read-timeout: 15000
      authentication: TOKEN
      token: s.E4gdoIYAKxMvCE56MP5Etmvy
      kv:
        enabled: true
        backend: secret
        backend-version: 2
        profile-separator: /
      generic:
          enabled: false
      application-name: myapp

配置服务器依赖性

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-vault-config</artifactId>
    <version>2.1.5.RELEASE</version>
</dependency>

.yml进入配置服务。然后进入我的微服务的.yml,我具有db.username属性,我想从Vault解析,但我不能。你有什么主意吗?

username: db.username
password: secret/apm-transaction-service/dev/db.user

@Value("${db.username}")

此值解析为Java代码,但不解析为.yml

现在,对于我拥有的每个微服务,我都想解决配置服务中的秘密,而无需对微服务进行任何更改。当前正在从配置服务中读取本机.ymls,并希望添加其他来源:)

ApplicationStartupRunner运行方法已启动!! root

1 个答案:

答案 0 :(得分:0)

如果使用的是spring-boot,则要解析的.yml文件中的值必须是变量。您必须在yaml文件中使用$ {db.username}