1. 实现 PropertySourceLocator 接口,比如:NacosPropertySourceLocator

2. 把实现注册到spring 容器

@Bean
    public NacosPropertySourceLocator nacosPropertySourceLocator(NacosConfigManager nacosConfigManager) {
        return new NacosPropertySourceLocator(nacosConfigManager);
    }

3.  PropertySourceBootstrapConfiguration会调用所有的PropertySourceLocator,做properties加载。

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(PropertySourceBootstrapProperties.class)
public class PropertySourceBootstrapConfiguration implements
        ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {

注:ApplicationContextInitializer的用途,在spring 容器刷新之前,会调用ApplicationContextInitializer.intialize()方法。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2022-03-09
  • 2021-08-10
  • 2022-12-23
  • 2021-09-25
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2021-10-29
  • 2022-01-15
  • 2021-09-07
相关资源
相似解决方案