首页 > 技术文章 > SpringCloud 整合Nacos注册和配置中心

ruhuanxingyun 2020-08-20 09:24 原文

简介:SpringCloud Alibaba Nacos是用来服务发现、配置和管理微服务,提供了管理界面。

1. pom.xml Maven依赖

<!-- Spring Cloud 配置中心 -->
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- Spring Cloud 服务注册中心 -->
<dependency>   <groupId>org.springframework.cloud</groupId>   <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>

2. bootstrap.yml 文件配置

spring:
    application:
        name: nacos
    cloud:
        inetutils:
            preferred-networks: 10.10.
        nacos:
            config:
                enabled: true
                namespace: ${spring.profiles.active}
          # 配置文件格式 file
-extension: yaml shared-configs: - data-id: rhxy.yaml group: GLOBAL refersh: true discovery: enabled: true namespace: ${spring.profiles.active} metadata: zone: primary # This is needed for the load balancer profile: ${spring.profiles.active} version: ${info.project.version:} git-version: ${git.commit.id.describe:} git-commit: ${git.commit.id.abbrev:} git-branch: ${git.branch:}

3. Nacos注解

  A. @EnableDiscoveryClient:启动注册中心;

  B. @RefreshScope:动态更新类的配置。

4. Nacos搭建与使用

  A. Nacos Docker部署

  B. 访问地址:http://localhost:8848/nacos/index.html;

  C. 创建命名空间。

 

 

可参考:Nacos官网文档

    SpringCloud2020整合Nacos-Bootstrap配置不生效的解决

推荐阅读