Spring Cloud Config和Spring Cloud Vault初始化顺序

时间:2018-02-14 22:42:41

标签: spring spring-boot spring-cloud spring-cloud-config spring-cloud-vault-config

我们正在利用Spring Cloud Config和Spring Cloud Config Vault。我们想知道是否有一种方法来引导引导程序,即我们希望弹出云配置服务器,然后从中提取属性以利用我们的保险库配置。我们查看了顺序,但它似乎没有工作,我认为这是因为后期处理顺序,但我希望我可能会遗漏一些东西。

2 个答案:

答案 0 :(得分:3)

TL; DR

它没有用。

说明

Spring Cloud对其引导上下文的作用是设置一个应用程序上下文,其中包含一组从Spring bean初始化的PropertySource。然后使用引导上下文作为Spring Boot创建的实际上下文的父上下文。属性查找在其自己的上下文和父上下文中查找属性。

配置属性在启动过程的早期初始化,它们使用当前Environment的属性。在初始化ConfigurationProperties个bean时,Environment尚未包含任何远程PropertySource

我在这里看到的唯一选项(创建bootstrap-bootstrap-context除外)是在main类中使用Spring Cloud Config客户端,并在构建任何Spring上下文之前提供Vault属性。

答案 1 :(得分:0)

可能可以,但是它需要PropertySourceBootstrapConfiguration#initialize()方法覆盖。您不能禁用bean PropertySourceBootstrapConfiguration,但是可以通过在applicationContext.getBeanFactory().getBean(PropertySourceBootstrapConfiguration.class).setPropertySourceLocators(new ArrayList<>())中使用CustomPropertySourceBootstrapConfiguration来禁用bean的initialize方法(以避免过时的外部属性源调用)。 在您的CustomPropertySourceBootstrapConfiguration#initialize方法中,您可以从config-server检索属性,然后通过插入在config-server secretId中生成的令牌来自定义vaultPropertySourceLocator。 不要忘记将CustomPropertySourceBootstrapConfiguration添加到spring.factories。

所以,这并不容易,但有可能。