源碼流程:
1、遍歷yaml配置的namespaces
2、每個namespace創(chuàng)建對應的config
3、第一次去遠程同步,拿到apollo配置信息。this.trySync();
1、先從http://dev.com:8080注冊中心拿到apollo-configservice的ip地址172.2.1.1.2:8080
2、再拿這個ip地址+namespace拼成http://172.2.1.1.2:8080/configs/admin-server/default/application?ip=172.2.2.3
3、拿拼好鏈接去請求apollo查詢配置信息
4、定時刷新。this.schedulePeriodicRefresh();
5、長輪詢刷新,獲取Apollo配置。 this.scheduleLongPollingRefresh();
6、將拿到的apollo配置信息寫到了Spring的類ConfigurableEnvironment中,供項目使用。environment.getPropertySources().addFirst(composite);
7、后面就可以通過Environtment.getProperty()獲取apollo中的屬性,Environment中還加入了別的propertySources,也都可以用Environment獲取
參考博客:
1、https://blog.csdn.net/xl649138628/article/details/122061806
2、https://blog.csdn.net/hhj13978064496/article/details/83031806