欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring-Cloud-Alibaba-Nacos-Discovery 安装使用

程序员文章站 2022-07-15 10:17:35
...

1. Nacos Server 安装

下载地址: `https://wwa.lanzous.com/iCRjPfkwd3i`
官网下载地址: `https://github.com/alibaba/nacos/releases`

下载安装完成之后运行 startup.cmd / startup.sh

2. Nacos client安装

2.1 引入坐标
<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR5</spring-cloud.version>
    <spring-cloud.alibaba.version>2.1.0.RELEASE</spring-cloud.alibaba.version>
</properties>
<!--spring cloud alibaba-->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring-cloud.alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
2.2 添加配置(application.yml)
server:
  # tomcat 端口 
  port: 7000
 
spring:
  application:
    # 应用名 
    name: gulimail-coupon
  cloud:
    nacos:
      discovery:
        # Nacos server 地址 默认端口为 8848
        server-addr: 127.0.0.1:8848 
2.3 添加注解
@EnableDiscoveryClient
@SpringBootApplication
public class GulimailCouponApplication {
    public static void main(String[] args) {
        SpringApplication.run(GulimailCouponApplication.class, args);
    }
}

启动器类加入注解@EnableDiscoveryClient

2.4 检验安装

浏览器访问 Nacos Server
输入localhost:8848/nacos

用户名: nacos
密码:   nacos

看到如下结果说明成功安装

Spring-Cloud-Alibaba-Nacos-Discovery 安装使用