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

      

      

  • 相关阅读:
    PostgreSQL Monitor pg_activity
    bzoj2333 [SCOI2011]棘手的操作
    bzoj1499 [NOI2005]瑰丽华尔兹
    bzoj2561 最小生成树
    bzoj2038 [2009国家集训队]小Z的袜子(hose)
    bzoj2002 [Hnoi2010]Bounce 弹飞绵羊
    bzoj3589 动态树
    bzoj4034 [HAOI2015]树上操作
    bzoj4774 修路
    2018.1.14 省选模拟赛
  • 原文地址:https://www.cnblogs.com/zhao907/p/13967738.html
Copyright © 2011-2022 走看看