@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Repeatable(value=VaultPropertySources.class) @Import(value=org.springframework.vault.annotation.VaultPropertySourceRegistrar.class) public @interface VaultPropertySource
VaultPropertySource
to Spring's
Environment
. To be used in conjunction
with @Configuration
classes.
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.
Modifier and Type | Required Element and Description |
---|---|
String[] |
value
Indicate the Vault path(s) of the properties to be retrieved.
|
Modifier and Type | Optional Element and Description |
---|---|
String |
vaultTemplateRef
Configure the name of the
VaultTemplate bean
to be used with the property sources. |
public abstract String[] value
"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.
public abstract String vaultTemplateRef
VaultTemplate
bean
to be used with the property sources.Copyright © 2016–2017 Pivotal Software, Inc.. All rights reserved.