9. 自定义要公开为 PropertySource 的密钥后端

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

发现的后端提供VaultSecretBackendDescriptorbean 来描述配置状态,以将 secret 后端用作PropertySource. 一个SecretBackendMetadataFactory需要创建一个SecretBackendMetadata包含路径、名称和属性转换配置的对象。spring-doc.cadn.net.cn

SecretBackendMetadata用于支持特定的PropertySource.spring-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()));