当前位置: 首页 > news >正文

自己的电脑做服务器搭建网站陕麻圈辅助软件

自己的电脑做服务器搭建网站,陕麻圈辅助软件,网站优化培训如何优化,网站设计公司本文收录于专栏 Nacos 推荐阅读#xff1a;Nacos 架构 原理 文章目录 前言一、NacosConfigBeanDefinitionRegistrar二、NacosPropertySourcePostProcessor三、AbstractNacosPropertySourceBuilder总结「AI生成」 前言 专栏前几篇文章主要讲了Nacos作为服务注册中心相关…本文收录于专栏 Nacos 推荐阅读Nacos 架构 原理 文章目录 前言一、NacosConfigBeanDefinitionRegistrar二、NacosPropertySourcePostProcessor三、AbstractNacosPropertySourceBuilder总结「AI生成」 前言 专栏前几篇文章主要讲了Nacos作为服务注册中心相关的代码本章开始梳理Nacos作为配置中心来使用时相关部分的代码主要逻辑。 ⚠️使用的Nacos版本为2.3.X ⚠️springboot集成Nacos dependencygroupIdcom.alibaba.boot/groupIdartifactIdnacos-config-spring-boot-starter/artifactIdversion0.2.12/version/dependency一、NacosConfigBeanDefinitionRegistrar 直接从spring.factories中找和心类NacosConfigAutoConfiguration ConditionalOnProperty(name NacosConfigConstants.ENABLED, matchIfMissing true) ConditionalOnMissingBean(name CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME) EnableConfigurationProperties(value NacosConfigProperties.class) ConditionalOnClass(name org.springframework.boot.context.properties.bind.Binder) Import(value { NacosConfigBootBeanDefinitionRegistrar.class }) EnableNacosConfig public class NacosConfigAutoConfiguration { }可以看到这个类里啥也没有核心就是引入EnableNacosConfig Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE }) Retention(RetentionPolicy.RUNTIME) Documented Import(NacosConfigBeanDefinitionRegistrar.class) public interface EnableNacosConfig {//一些配置文件中nacos配置的占位符定义 }我们来看关键类NacosConfigBeanDefinitionRegistrar Override public void registerBeanDefinitions(AnnotationMetadata metadata,BeanDefinitionRegistry registry) {AnnotationAttributes attributes fromMap(metadata.getAnnotationAttributes(EnableNacosConfig.class.getName()));// Register Global Nacos Properties BeanregisterGlobalNacosProperties(attributes, registry, environment,CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME);// Register Nacos Common BeansregisterNacosCommonBeans(registry);// Register Nacos Config BeansregisterNacosConfigBeans(registry, environment, beanFactory);// Invoke NacosPropertySourcePostProcessor immediately// in order to enhance the precedence of NacosPropertySource processinvokeNacosPropertySourcePostProcessor(beanFactory); }invokeNacosPropertySourcePostProcessor上边的代码处理的都是和spring集成相关的逻辑我们这里暂不去展开。invokeNacosPropertySourcePostProcessor通过这个名字我们可以简单看出来这个方法处理的是post processor一些后置逻辑。 二、NacosPropertySourcePostProcessor public static void invokeNacosPropertySourcePostProcessor(BeanFactory beanFactory) {NacosPropertySourcePostProcessor postProcessor beanFactory.getBean(//nacosPropertySourcePostProcessorNacosPropertySourcePostProcessor.BEAN_NAME,NacosPropertySourcePostProcessor.class);postProcessor.postProcessBeanFactory((ConfigurableListableBeanFactory) beanFactory); }代码看到这里我们做个暂停再次想一想我们到底要找什么有了明确的方向才不至于在洋洋洒洒的源码里一头雾水。 那么我们到底要找什么 对我们想要知道的是Nacos是如何给NacosValue标注的字段赋值的。 然后再来看代码是否就清晰了一点 对代码中的关键词就是process 那就继续看postProcessor.postProcessBeanFactory((ConfigurableListableBeanFactory) beanFactory); Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)throws BeansException {String[] abstractNacosPropertySourceBuilderBeanNames BeanUtils.getBeanNames(beanFactory, AbstractNacosPropertySourceBuilder.class);this.nacosPropertySourceBuilders new ArrayListAbstractNacosPropertySourceBuilder(abstractNacosPropertySourceBuilderBeanNames.length);for (String beanName : abstractNacosPropertySourceBuilderBeanNames) {this.nacosPropertySourceBuilders.add(beanFactory.getBean(beanName,AbstractNacosPropertySourceBuilder.class));}NacosPropertySourcePostProcessor.beanFactory beanFactory;this.configServiceBeanBuilder getConfigServiceBeanBuilder(beanFactory);String[] beanNames beanFactory.getBeanDefinitionNames();for (String beanName : beanNames) {processPropertySource(beanName, beanFactory);} }有了关键词那我们就继续看processPropertySource(beanName, beanFactory); private void processPropertySource(String beanName,ConfigurableListableBeanFactory beanFactory) {//processedBeanNames记录的是已经处理过的beanName, 看下这个方法的最后一行就知道了。if (processedBeanNames.contains(beanName)) {return;}//BeanDefinition通过spring factory获取的bean定义类BeanDefinition beanDefinition beanFactory.getBeanDefinition(beanName);// Build multiple instance if possibleListNacosPropertySource nacosPropertySources buildNacosPropertySources(beanName, beanDefinition);// Add Orderlyfor (NacosPropertySource nacosPropertySource : nacosPropertySources) {addNacosPropertySource(nacosPropertySource);Properties properties configServiceBeanBuilder.resolveProperties(nacosPropertySource.getAttributesMetadata());addListenerIfAutoRefreshed(nacosPropertySource, properties, environment);}processedBeanNames.add(beanName); }private ListNacosPropertySource buildNacosPropertySources(String beanName,BeanDefinition beanDefinition) {for (AbstractNacosPropertySourceBuilder builder : nacosPropertySourceBuilders) {if (builder.supports(beanDefinition)) {return builder.build(beanName, beanDefinition);}}return Collections.emptyList(); }builder.build(beanName, beanDefinition) 我们来着重看下这个方法 三、AbstractNacosPropertySourceBuilder 我们看下这个build方法的具体实现 public ListNacosPropertySource build(String beanName, T beanDefinition) {MapString, Object[] attributesArray resolveRuntimeAttributesArray(beanDefinition, globalNacosProperties);int size attributesArray null ? 0 : attributesArray.length;if (size 0) {return Collections.emptyList();}ListNacosPropertySource nacosPropertySources new ArrayListNacosPropertySource(size);for (int i 0; i size; i) {MapString, Object attributes attributesArray[i];if (!CollectionUtils.isEmpty(attributes)) {NacosPropertySource nacosPropertySource doBuild(beanName,beanDefinition, attributesArray[i]);NacosConfigMetadataEvent metadataEvent createMetaEvent(nacosPropertySource, beanDefinition);initMetadataEvent(nacosPropertySource, beanDefinition, metadataEvent);publishMetadataEvent(metadataEvent);nacosPropertySources.add(nacosPropertySource);}}return nacosPropertySources; }这个方法返回的是ListNacosPropertySource而NacosPropertySource是在doBuild(beanName,beanDefinition, attributesArray[i]);这里给出的那就着重看下这里的实现。 ps: 篇幅限制只给出重要代码 protected NacosPropertySource doBuild(String beanName, T beanDefinition,MapString, Object runtimeAttributes) {//。。。String nacosConfig nacosConfigLoader.load(dataId, groupId, nacosProperties);//。。。NacosPropertySource nacosPropertySource new NacosPropertySource(dataId, groupId,name, nacosConfig, type);//。。。 }NacosPropertySource中存放配置的位置 这个方法主要做了两件事 获取 nacosConfig。我们知道Nacos客户端在第一次获取数据的时候会去server端全量拉取一次那所以这里肯定有和服务端交互的逻辑。生成NacosPropertySource这是doBuild要返回的数据。 总结「AI生成」 本文分析了Nacos客户端源码重点探讨了Nacos作为配置中心的主要逻辑。以下是关键类的描述和功能总结 NacosConfigAutoConfiguration 位于Spring的spring.factories中负责自动配置Nacos。虽然类本身不包含逻辑但通过EnableNacosConfig注解引入了Nacos配置的核心类NacosConfigBeanDefinitionRegistrar。 NacosConfigBeanDefinitionRegistrar 负责注册Nacos的相关Bean定义。主要方法registerBeanDefinitions包括注册全局Nacos属性、Nacos通用Bean和Nacos配置Bean并调用NacosPropertySourcePostProcessor处理后置逻辑。 NacosPropertySourcePostProcessor 通过invokeNacosPropertySourcePostProcessor方法调用负责后置处理逻辑主要处理配置源的加载和Nacos属性的解析。其核心方法postProcessBeanFactory遍历所有Bean定义并处理Nacos配置源。 AbstractNacosPropertySourceBuilder 通过build方法构建NacosPropertySource。该方法首先解析运行时属性数组然后根据属性构建Nacos配置源。核心方法doBuild实现了与Nacos服务端的交互获取配置数据并生成NacosPropertySource。 NacosPropertySource 存放从Nacos服务端获取的配置数据是Nacos配置管理的核心数据结构。 本文通过深入分析这些关键类和方法揭示了Nacos客户端在作为配置中心时的工作机制特别是如何通过NacosValue注解为字段赋值的流程。
http://www.hkea.cn/news/14394860/

相关文章:

  • 有后台的网站如何建设柳州企业网站建设
  • 电子商务网站建设与维护 书做优惠券网站要多少钱
  • 网站建设的目的模板驻马店 市网站建设
  • 建设网站教程视频公司总经理培训推广哪家好
  • 购物网站建设精英网站建设付款方式
  • 中国建设银行官网站e路护航重庆网站推广优化
  • 江苏建设工程造价管理网站企业宣传片拍摄制作
  • 网站首页布局seo策划公司活动方案
  • 怎样把自己的网站推广出去提高销售的10种方法
  • 肉山谷英雄传说新手任务登录英文网站怎么做老牛影视传媒有限公司
  • 国内站长做国外网站现在如何给网站做外链
  • 做网站选哪家公司没固定ip怎么做网站
  • 宣传网站怎么做的设计网站建设书南昌
  • 网站注册域名位置网站设计风格的关键词
  • 外国做的福利小视频在线观看网站广告拍摄制作公司
  • 辽宁网站建设企业织梦模板首页修改教程
  • 网站数据采集怎么做池州网站建设电话
  • seo站长教程筑业网
  • 手机网站设计创意说明设计常用网站
  • 网站如何做修改密码的相关验证开发一款彩票app需要多少钱
  • 免费网站论坛网站批量创建程序
  • 彩票网站建设维护wordpress支持微信登录
  • 门户网站做等级保护测评网站模板 自适应
  • 酒店和网站对接如何做域名不用了需要注销吗
  • 广东哪家网站建设后台管理便捷企业管理专业主要课程
  • 东莞网站优化公司推荐建设网站网站建站
  • 东莞倣网站在线识图
  • 网站优化技巧360建设网站免费下载
  • 天津网站建设哪家公司好网络营销公司模拟创建实训
  • dz论坛做视频网站教程深圳建设交易平台官网