• 从 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;
    
    }
  • 相关阅读:
    [LeetCode] Dungeon Game
    [LeetCode] Maximal Rectangle
    [LeetCode] Scramble String -- 三维动态规划的范例
    [LeetCode] Palindrome Partitioning II
    [LeetCode] Palindrome Partitioning
    [LeetCode] Interleaving String
    [LeetCode] Longest Valid Parentheses -- 挂动态规划羊头卖stack的狗肉
    JPA将查询结果转换为DTO对象
    EOS签名R值过大导致报错"is_canonical( c ): signature is not canonical"
    比特币中P2SH(pay-to-script-hash)多重签名的锁定脚本和解锁脚本
  • 原文地址:https://www.cnblogs.com/allenwas3/p/11354103.html
Copyright © 2020-2023  润新知