Annotation Interface VaultPropertySource


@Target(TYPE) @Retention(RUNTIME) @Documented @Repeatable(VaultPropertySources.class) @Import(org.springframework.vault.annotation.VaultPropertySourceRegistrar.class) public @interface VaultPropertySource
Annotation providing a convenient and declarative mechanism for adding a VaultPropertySource to Spring's Environment. To be used in conjunction with @Configuration classes.

Example usage

Given a Vault path secret/my-application containing the configuration data pair database.password=mysecretpassword, the following @Configuration class uses @VaultPropertySource to contribute secret/my-application to the Environment's set of PropertySources.

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

        @Autowired
        Environment env;

        @Bean
        public TestBean testBean() {
                TestBean testBean = new TestBean();
                testBean.setPassword(env.getProperty("database.password"));
                return testBean;
        }
 }
 
Notice that the Environment object is @Autowired into the configuration class and then used when populating the TestBean object. Given the configuration above, a call to testBean.getPassword() will return "mysecretpassword".

In certain situations, it may not be possible or practical to tightly control property source ordering when using @VaultPropertySource annotations. For example, if the @Configuration classes above were registered via component-scanning, the ordering is difficult to predict. In such cases - and if overriding is important - it is recommended that the user fall back to using the programmatic PropertySource API. See ConfigurableEnvironment and MutablePropertySources javadocs for details.

Author:
Mark Paluch
See Also:
  • Element Details

    • value

      String[] value
      Indicate the Vault path(s) of the secret to be retrieved. For example, "secret/myapp" or "secret/my-application/profile".

      Each location will be added to the enclosing Environment as its own property source, and in the order declared.

    • propertyNamePrefix

      String propertyNamePrefix
      Property name prefix for properties obtained from Vault. All properties will be prefixed with propertyNamePrefix.
      Default:
      ""
    • ignoreSecretNotFound

      boolean ignoreSecretNotFound
      Indicate if failure to find the secrets should be ignored.

      true is appropriate if the secrets are completely optional. Default is true.

      Since:
      2.2.
      Default:
      true
    • vaultTemplateRef

      String vaultTemplateRef
      Configure the name of the VaultTemplate bean to be used with the property sources.
      Default:
      "vaultTemplate"
    • renewal

      Configure lease renewal/rotation.
      Default:
      OFF