Java 春云穹顶。在没有Vault的环境中Vault PropertySource出现问题
我有一个带有Java 春云穹顶。在没有Vault的环境中Vault PropertySource出现问题,java,spring-boot,spring-cloud-vault-config,Java,Spring Boot,Spring Cloud Vault Config,我有一个带有VaultPropertySource注释的配置类,类似于下面的注释,它在可以访问Vault的环境中非常有效 @Configuration @VaultPropertySource("secret/my-application") public class AppConfig { @Value(${redis.password:default}) private String password } 问题是,某些部署将无法访问Vault。在我的bootstrap
VaultPropertySource
注释的配置类,类似于下面的注释,它在可以访问Vault的环境中非常有效
@Configuration
@VaultPropertySource("secret/my-application")
public class AppConfig {
@Value(${redis.password:default})
private String password
}
问题是,某些部署将无法访问Vault。在我的bootstrap.yml
中,我设置了spring.cloud.vault.enabled=false
,但是我得到了
应用程序启动失败-找不到名为“vaultTemplate”的组件
此时,我可以注释掉VaultPropertySource
,它就可以工作了。在这些没有Vault的环境中,我可以做什么而不必注释掉VaultPropertySource
?用于有条件地在应用程序中启用Vault等方面。默认情况下,您可以在bootstrap.yml
中禁用Vault,并通过另一个启用Vault集成的配置(例如bootstrap Vault.yml
)重新启用它
通过使用@Profile(…)
将相同的模式应用于AppConfig
,将有条件地应用@VaultPropertySource
,并消除提供VaultTemplate
@Configuration
@VaultPropertySource("secret/my-application")
@Profile("vault")
public class AppConfig {
@Value(${redis.password:default})
private String password
}