简体   繁体   English

Spring 云库配置文件特定引导程序

[英]Spring Cloud Vault Profile Specific Bootstrap

I have a Spring Boot Application and I would like to Load configurations from Vault based on the Profile I am running.我有一个 Spring 引导应用程序,我想根据我正在运行的配置文件从 Vault 加载配置。 At present i have 2 profiles (dev, prod).目前我有 2 个配置文件(开发、产品)。 My Dev Profile uses a H2 database where as the Prod Profile uses a Posgres DB.我的 Dev Profile 使用 H2 数据库,而 Prod Profile 使用 Posgres DB。 Running the dev Profile loads the correct config from Vault but running with the Prod Profile seems to be skipping it somehow and not looking in Vault.运行开发配置文件会从 Vault 加载正确的配置,但使用 Prod 配置文件运行似乎会以某种方式跳过它,而不是查看 Vault。

bootstrap.yaml引导程序.yaml

spring:
  application:
    name: my-app
  profiles:
    active:
  cloud:
    vault:
      host: localhost
      port: 8200
      scheme: http
      uri: http://localhost:8200
      connection-timeout: 5000
      read-timeout: 15000
      authentication: TOKEN
      token: 00000000-0000-0000-0000-000000000000
      kv:
        enabled: true
        backend: secret
        default-context: my-app/dev
      fail-fast: false

bootstrap-prod.yaml引导-prod.yaml

spring:
  application:
    name: gateway
  profiles:
    active: prod
  cloud:
    vault:
      host: localhost
      port: 8200
      scheme: http
      uri: http://localhost:8200
      connection-timeout: 5000
      read-timeout: 15000
      authentication: TOKEN
      token: 00000000-0000-0000-0000-000000000000
      kv:
        enabled: true
        backend: secret
        default-context: my-app/dev
      fail-fast: false

For example running the command gradle will load configuration from vault.例如,运行命令gradle将从保管库加载配置。 But running gradle -Pprod fails to load the correct configuration from Vault.但是运行gradle -Pprod无法从 Vault 加载正确的配置。

try this syntax to activate your profile when using gradle:在使用 gradle 时尝试使用以下语法来激活您的配置文件:

./gradlew clean bootRun --args='--spring.profiles.active=prod'

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

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