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);
        }
    }
    

      

      

  • 相关阅读:
    linux开机自启动服务优化设置命令
    yum网络源配置
    CentOS 6一键系统优化 Shell 脚本
    linux系统下find删除目录下除一文件外的所有文件
    linux系统时间同步
    Memcached 查询stats及各项状态解释
    VMWARE 12安装Tools
    win8及以上2012 R2,virtualbox 5.0.20安装centOS6以上各种注意事项
    HTTP的上传文件实例分析
    java中类加载顺序(深入Java)
  • 原文地址:https://www.cnblogs.com/zhao907/p/13967738.html
Copyright © 2011-2022 走看看