2

I have a configuration class with VaultPropertySource annotation similar to the following that works great in environments that have access to Vault.

@Configuration  
@VaultPropertySource("secret/my-application")
public class AppConfig {

    @Value(${redis.password:default})
    private String password
}

The issue is that some deployments will not have access to Vault. In my bootstrap.yml I have set spring.cloud.vault.enabled = false but I get

Application failed to start - A component required a been named 'vaultTemplate' that could not be found.

At this point, I can comment out the VaultPropertySource and it works. What can I do in these environments without Vault without having to comment out VaultPropertySource?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
chutcher
  • 586
  • 6
  • 11

1 Answers1

2

Use Spring profiles to conditionally enable aspects such as Vault in your application. You can disable Vault by default in bootstrap.yml and re-enable it by having another config (e.g. bootstrap-vault.yml) that enables the Vault integration.

Applying the same pattern to AppConfig by using @Profile(…) would conditionally apply @VaultPropertySource and remove the need to provide VaultTemplate

@Configuration  
@VaultPropertySource("secret/my-application")
@Profile("vault")
public class AppConfig {

    @Value(${redis.password:default})
    private String password
}
mp911de
  • 17,546
  • 2
  • 55
  • 95