zoukankan      html  css  js  c++  java
  • Naocs 配置中心报错问题

     Nacos 配置:

     

    Spring Cloud VersionSpring Cloud Alibaba VersionSpring Boot Version

    Spring Cloud Hoxton.SR8

    2.2.3.RELEASE

    2.3.2.RELEASE

    Spring Cloud Greenwich.SR6

    2.1.3.RELEASE

    2.1.13.RELEASE

    Spring Cloud Hoxton.SR8

    2.2.2.RELEASE

    2.3.2.RELEASE

    Spring Cloud Hoxton.SR3

    2.2.1.RELEASE

    2.2.5.RELEASE

    Spring Cloud Hoxton.RELEASE

    2.2.0.RELEASE

    2.2.X.RELEASE

    Spring Cloud Greenwich

    2.1.2.RELEASE

    2.1.X.RELEASE

    Spring Cloud Finchley

    2.0.3.RELEASE

    2.0.X.RELEASE

    Spring Cloud Edgware

    1.5.1.RELEASE(停止维护,建议升级)

    1.5.X.RELEASE

    pom.xml文件添加包:

    <!--nacos-config-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    
    <!--nacos-discovery-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    

      



    bootstrap.yml优先于application.yml
    bootstrap.yml配置:
    server:
      port: 3377
    
    spring:
      application:
        name: nacos-config-client
      cloud:
        nacos:
          discovery:
            server-addr: localhost:8848 # 服务注册中心地址
          config:
            server-addr: localhost:8848 #配置中心地址
            file-extension: yaml #指定yaml格式的配置
            #group: TEST_GROUP #默认:DEFAULT_GROUP
            #namespace: 00ab1957-eb3f-4555-96ca-3d20817e854d #命名空间id 默认:public
    
    # ${spring.application.name}-${spring.profile.active}.${spring.cloud.nacos.config.file-extension}
    # nacos-config-client-dev.yaml
    
    application.yml配置:
    spring:
      profiles:
        active: dev # 表示激活开发环境
    

      类配置:

    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.cloud.context.config.annotation.RefreshScope;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    
    @RestController
    @RefreshScope //支持controller的动态刷新
    public class ConfigClientController
    {
        @Value("${config.info}")
        private String configInfo;
    
        @GetMapping("/config/info")
        public String getConfigInfo() {
            return configInfo;
        }
    }
    

      启动类:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    
    @EnableDiscoveryClient
    @SpringBootApplication
    public class NacosConfigClientApp {
    
        public static void main(String[] args) {
            SpringApplication.run(NacosConfigClientApp.class,args);
        }
    }
    

      

      

  • 相关阅读:
    SQL Server 之 在与SQLServer建立连接时出现与网络相关的或特定于实例的错误
    T-SQL 之 概述
    HTML 之 Web页面表单form中只有一个input的text元素,按回车默认提交
    CollatingOfData 之 JsonHelper
    JavaScript 之 弹出窗口总结
    JavaScript 之 页面跳转及Frame动态加载
    XML 之 与Json或String的相互转换
    UML 之 类图(Class Dragram)
    Asp.Net 之 调用分享接口
    echo print() print_r() var_dump()的区别
  • 原文地址:https://www.cnblogs.com/zhao907/p/13967738.html
Copyright © 2011-2022 走看看