• Nacos - 配置中心&注册中心


    1 作为配置中心

    1.1 启动nacos

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

    1.2 集成在spingcloud项目中

    1.2.1 引入pom

    1. <dependency>
    2.          <groupId>org.springframework.boot</groupId>
    3.          <artifactId>spring-boot-starter-actuator</artifactId>
    4. </dependency>
    5. <dependency>
    6.          <groupId>org.springframework.cloud</groupId>
    7.          <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    8.          <version>0.2.2.RELEASE</version>
    9. </dependency>

    1.2.2 bootstrap.yaml

    1. spring:
    2. cloud:
    3. nacos:
    4. config:
    5. server-addr: 127.0.0.1:8848
    6. file-extension: yaml
    7. shared-dataids: nacos-config.yaml,spm-nacos-config-develop.yaml,spm-nacos-config-prod.yaml
    8. refreshable-dataids: nacos-config.yaml,spm-nacos-config-develop.yaml,spm-nacos-config-prod.yaml
    9. application:
    10. name: spm-nacos-config
    11. profiles:
    12. active: prod
    13. management:
    14. endpoints:
    15. web:
    16. exposure:
    17. 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项目中

    1. <dependency>
    2. <groupId>org.springframework.cloud</groupId>
    3. <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    4. <version>0.2.2.RELEASE</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>org.springframework.boot</groupId>
    8. <artifactId>spring-boot-starter-actuator</artifactId>
    9. </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

    我本地启动了两个服务

  • 相关阅读:
    SpringSecurity框架
    CS110L(Rust)
    左耳听风 笔记
    极狐GitLab CI x Vault,做好企业密钥安全合规管理
    21天学习挑战:经典算法---希尔排序
    递归乘法00
    tree型数组平铺,一维数组结构tree型
    【数据结构】并查集
    golang验证Etherscan上的智能合约
    下载工程resources目录下的模板excel文件
  • 原文地址:https://blog.csdn.net/hutuyaoniexi/article/details/126484829