Annotation Interface VaultPropertySource
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:
-
Nested Class Summary
-
Required Element Summary
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Indicate if failure to find thesecrets
should be ignored.Property name prefix for properties obtained from Vault.Configure lease renewal/rotation.Configure the name of theVaultTemplate
bean to be used with the property sources.
-
Element Details
-
value
String[] valueIndicate 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 propertyNamePrefixProperty name prefix for properties obtained from Vault. All properties will be prefixed withpropertyNamePrefix
.- Default:
- ""
-
ignoreSecretNotFound
boolean ignoreSecretNotFoundIndicate if failure to find thesecrets
should be ignored.true is appropriate if the secrets are completely optional. Default is true.
- Since:
- 2.2.
- Default:
- true
-
vaultTemplateRef
String vaultTemplateRefConfigure the name of theVaultTemplate
bean to be used with the property sources.- Default:
- "vaultTemplate"
-
renewal
VaultPropertySource.Renewal renewalConfigure lease renewal/rotation.- Default:
- OFF
-