Search code examples
springspring-boothashicorp-vaultspring-cloud-vault-configspring-vault

Spring Cloud Vault use local env variable when not in production for API Key


I am using Spring Cloud Vault to store an API Key in production.

From reading the spring.io blog it appears I can use

 @Value("${apiKey}")
 String apiKey;

to access that key in vault.

This is fine when in production, but is there a way that I can set a default value/ some other way of setting up an apiKey that can be used locally for development? (preferably outside of vault if possible)


Solution

  • As explained in the Spring Boot Reference Guide several sources of configuration properties are consulted. It doesn't really matter where the value for apiKey comes from.

    You have at least 3 options:

    1. Set it in the environment,
    2. Pass it as an argument with --apiKey=<your-api-key> when starting the application locally
    3. simply place it in an application.[properties|yaml] used for local development.

    Either way the apiKey property will be resolved locally without having to use the vault.