zoukankan      html  css  js  c++  java
  • 从 spring-cloud-alibaba-nacos-config 进入 nacos-client

    sc 的 bootstrap context 是 main application context 的 parent,需要在 main application context 中使用的 bean 可以在

    spring-cloud-alibaba-nacos-config/META-INF/spring.factories 文件中定义:

    org.springframework.cloud.bootstrap.BootstrapConfiguration=
    org.springframework.cloud.alibaba.nacos.NacosConfigBootstrapConfiguration
    org.springframework.boot.autoconfigure.EnableAutoConfiguration=
    org.springframework.cloud.alibaba.nacos.NacosConfigAutoConfiguration,
    org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpointAutoConfiguration
    org.springframework.boot.diagnostics.FailureAnalyzer=
    org.springframework.cloud.alibaba.nacos.diagnostics.analyzer.NacosConnectionFailureAnalyzer

    BootstrapConfiguration 对应 sc 的 bootstrap context。

    EnableAutoConfiguration 是 spring boot 的自动配置注解。

    spring.factories 文件的解析在 SpringFactoriesLoader 类中。

    NacosConfigBootstrapConfiguration

    @Configuration // 创建 bean
    @ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
    public class NacosConfigBootstrapConfiguration {
    
        @Bean // 创建 bean
        @ConditionalOnMissingBean
        public NacosConfigProperties nacosConfigProperties() {
            return new NacosConfigProperties();
        }
    
        @Bean
        public NacosPropertySourceLocator nacosPropertySourceLocator(
                NacosConfigProperties nacosConfigProperties) {
            return new NacosPropertySourceLocator(nacosConfigProperties);
        }
    
    }

    spring boot 实体类装载配置文件信息

    @ConfigurationProperties(NacosConfigProperties.PREFIX)
    public class NacosConfigProperties {
    
        public static final String PREFIX = "spring.cloud.nacos.config";
    
        private static final Logger log = LoggerFactory
                .getLogger(NacosConfigProperties.class);
    
        /**
         * nacos config server address
         */
        private String serverAddr;
    
    }
  • 相关阅读:
    《基于Android的大学学生信息查询系统设计与实现》论文笔记(十二)
    《课程安排管理系统分析与设计》论文笔记(十一)
    第十次读书笔记 软件工程:方法与实践
    结对作业收获_core组
    软件工程:方法与实践 第七次读书笔记
    结对作业_core组
    软件工程:方法与实践 第六次读书笔记
    第五周课后作业
    软件工程 :方法与实践 第五次读书笔记
    个人作业—词频统计
  • 原文地址:https://www.cnblogs.com/allenwas3/p/11354103.html
Copyright © 2011-2022 走看看