Nacos – 配置中心&注册中心

导读:本篇文章讲解 Nacos – 配置中心&注册中心,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

1 作为配置中心

1.1 启动nacos

启动后登录: http://127.0.0.1:8848/nacos/index.html 用户名:nacos 密码:nacos

Nacos - 配置中心&注册中心

1.2 集成在spingcloud项目中

1.2.1 引入pom

<dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
         <version>0.2.2.RELEASE</version>
</dependency>

1.2.2 bootstrap.yaml

spring:
  cloud:
    nacos:
      config:
        server-addr: 127.0.0.1:8848
        file-extension: yaml
        shared-dataids: nacos-config.yaml,spm-nacos-config-develop.yaml,spm-nacos-config-prod.yaml
        refreshable-dataids: nacos-config.yaml,spm-nacos-config-develop.yaml,spm-nacos-config-prod.yaml
  application:
    name: spm-nacos-config
  profiles:
    active: prod
management:
  endpoints:
    web:
      exposure:
        exclude: "*"

1.3 在nacos控制台添加一个配置

参考官方文档:https://nacos.io/zh-cn/docs/quick-start.html

nacos支持多环境配置 例如:dev,test,prod

1.4 启动项目

启动控制会看到:in develop-env enviroment; user name :test; age: 26

已经从nacos拿到了配置

2019-11-13 11:48:25.608  INFO 32602 — [           main] c.h.s.config.SpmNacosConfigApplication:Started SpmNacosConfigApplication in 3.133 seconds (JVM running for 3.72)in develop-env enviroment;user name:test;age:26

2 作为注册中心

2.1 集成在spingcloud项目中

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>0.2.2.RELEASE</version>
</dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>![image-20191113114308300.png](https://upload-images.jianshu.io/upload_images/11541995-cc7b771a6c2026dc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

2.2 启动类添加注解

@EnableDiscoveryClient

2.3 启动服务查看nacos控制界面

访问地址:http://127.0.0.1:8082/actuator/nacos-discovery

我本地启动了两个服务

Nacos - 配置中心&注册中心

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/117235.html

(0)
seven_的头像seven_bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!