我在bootstrap.yml
文件中提到了Spring Cloud Vault配置
spring:
cloud:
vault:
authentication: APPROLE
app-role:
role-id: *****
secret-id: ****
host: ****
port: 80
scheme: http
但是我不想将这些存储在我的YML文件中,而是希望将它们配置为bean
@configuration / @bean
请帮助。谢谢
答案 0 :(得分:0)
我能够通过配置类型Bean
的{{1}}成功地做到这一点。下面是完全消除了在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