SpringCloud 之 Nacos使用流程

Nacos下载和安装

1. 下载地址

下载地址:https://github.com/alibaba/nacos/releases
下载版本:nacos-server-1.1.4.tar.gz或nacos-server-1.1.4.zip,解压任意目录即可
------注:当前SpringBoot版本为2.2.1.RELEASE

2. 启动

1.Linux/Unix/Mac
----启动命令:sh startup.sh -m standalone (standalone代表着单机模式运行,非集群模式)
2.Windows
----启动命令:cmd startup.cmd 或者双击startup.cmd运行文件。

在这里插入图片描述
3. 访问

访问地址:http://localhost:8848/nacos
用户名密码:nacos/nacos

服务注册

1. 引入依赖

----工程结构:

guli_parent
    common  (公共模块)
    service (服务模块)
        service-edu (模块1--主要业务模块)
        service-oss (模块2--文件模块)
        service-vod (模块3--视频模块)

----guli_parent设置依赖版本

<properties>
    <cloud-alibaba.version>0.2.2.RELEASE</cloud-alibaba.version>
</properties>

<dependencyManagement>
    <dependencies>
        <!--Spring Cloud  当前SpringBoot版本为2.2.1.RELEASE-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${cloud-alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

----service模块引入依赖

<!--服务注册-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

2. application配置

# 服务名  该名称会显示在Nacos中的服务列表
spring.application.name=service-edu   # 服务名不要加下划线"_"
......
# nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

3. 加启动注解

在微服务启动类上加此注解:
    @EnableDiscoveryClient

4. Nacos服务列表
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值