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()方法。