9. 自定义要作为PropertySource暴露的密钥后端

Spring Cloud Vault 使用基于属性的配置为键值和发现的密后端创建 PropertySources。spring-doc.cadn.net.cn

发现的后端提供VaultSecretBackendDescriptor个豆以描述使用秘密后端的配置状态为PropertySource。 一个SecretBackendMetadataFactory是创建SecretBackendMetadata对象所必需的,该对象包含路径、名称和属性转换配置。spring-doc.cadn.net.cn

SecretBackendMetadata用于支持特定的PropertySourcespring-doc.cadn.net.cn

你可以为自定义设置注册一个VaultConfigurer。 如果你提供一个VaultConfigurer,则默认的键值和后端发现的注册将被禁用。 不过你也可以通过SecretBackendConfigurer.registerDefaultKeyValueSecretBackends()SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends()启用默认注册。spring-doc.cadn.net.cn

public class CustomizationBean implements VaultConfigurer {

    @Override
    public void addSecretBackends(SecretBackendConfigurer configurer) {

        configurer.add("secret/my-application");

        configurer.registerDefaultKeyValueSecretBackends(false);
        configurer.registerDefaultDiscoveredSecretBackends(true);
    }
}
SpringApplication application = new SpringApplication(MyApplication.class);
application.addBootstrapper(VaultBootstrapper.fromConfigurer(new CustomizationBean()));