0

我在我的bootstrap.yml文件中提到了 Spring Cloud Vault 配置

spring:
  cloud:
    vault:
      authentication: APPROLE
      app-role:
        role-id: *****
        secret-id: ****
      host: ****
      port: 80
      scheme: http

但我不想在我的 YML 文件中包含这些,而是​​希望将它们配置为 bean

@配置/@bean

请帮忙。谢谢

4

1 回答 1

2

我能够通过配置一个Bean类型成功地做到这一点VaultProperties。下面是代码片段,它完全消除了在bootstrap.yml

@Configuration
public class VaultConfiguration {

    @Bean
    public VaultProperties vaultProperties() {

        VaultProperties vaultProperties = new VaultProperties();

        vaultProperties.setAuthentication(VaultProperties.AuthenticationMethod.APPROLE);

        VaultProperties.AppRoleProperties appRoleProperties = new VaultProperties.AppRoleProperties();
        appRoleProperties.setRoleId("****");
        appRoleProperties.setSecretId("****");

        vaultProperties.setAppRole(appRoleProperties);
        vaultProperties.setHost("***");
        vaultProperties.setPort(80);
        vaultProperties.setScheme("http");

        return vaultProperties;
    }
}

注意:当您有一个应该被视为引导配置的配置时,您需要在下面提及类名src/main/resources/META-INF/spring.factories

里面的内容spring.factories

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.arun.local.cloudconfig.VaultConfiguration
于 2018-08-31T09:01:20.420 回答