springcloudalibaba nacos客户端 自动获取配置 启动流程
1.spring.factories中有引导程序配置项:org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration,\
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration
引导程序配置项相当于application中的autoconfiguration配置,在bootstrap中使用。
2.com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration会注册2个bean
nacosConfigProperties
nacosPropertySourceLocator
3.nacosConfigProperties会自动加载spring.cloud.nacos.config的配置项目,这里定义了nacos config服务器的连接信息, 需访问的配置项信息
4.nacosPropertySourceLocator的locate方法会实例化一个configService(),创建nacosPropertySourceBuilder,
nacosPropertySourceBuilder里封装了对nacos config服务器的访问,通过配置属性生成nacos配置项名称
locate方法由bootstrap上下文的SpringApplication.prepareContext方法中的applyInitializers里的PropertySourceBootstrapConfiguration.initialize调用
4.1实例化一个configService