> 文章列表 > 【nacos配置中心】源码部分解析

【nacos配置中心】源码部分解析

【nacos配置中心】源码部分解析

启动初始化

SpringApplication.prepareContext

在这里插入图片描述
在这里插入图片描述

applyInitializers

回调ApplicationContextInitializer的initialize方法
在这里插入图片描述

getInitializers()从applicationContext获取List<ApplicationContextInitializer<?>> initializers
在这里插入图片描述
这个集合是通过SpringApplication的构造方法初始化
同样在这里也会初始化加载ApplicationListener事件监听器

在这里插入图片描述

PropertySourceBootstrapConfiguration.initialize

遍历propertySourceLocators,执行locator的locateCollection方法
在这里插入图片描述
NacosPropertySourceLocator实现了propertySourceLocators
在这里插入图片描述

NacosPropertySourceLocator.locate

在这里插入图片描述

loadSharedConfiguration

加载shared配置
在这里插入图片描述
通过nacosConfigProperties读取sharedConfigs配置,在这里如果我们封装脚手架,可以通过系统设置默认配置读取
在这里插入图片描述

扩展:nacos自定义配置yaml文件读取

自定义读取配置,可以配置默认的 xxx.yaml
在这里插入图片描述
启动时装载
在这里插入图片描述

读取dataId数据

获取到sharedConfigs之后
在这里插入图片描述通过dataId获取数据
在这里插入图片描述
configService.getConfig通过grpc去服务端拉取配置并返回,具体代码省略