springcloud-alibaba接入nacos注册中心

1,引入依赖,所有模块都要用到,多模块里可以将依赖放到父模块或者公用模块

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

2,windows版nacos 中间件安装 ,
(1) 直接下载编译好的release版的
(2)github下不了的,可以到gitee拉取源码,指定版本的tag,不要拉取最新的,进行编译。因为nacos也是java语言开发的。

官网教程:https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html

git clone https://github.com/alibaba/nacos.git
cd nacos/
mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U  
ls -al distribution/target/

// change the $version to your actual path
cd distribution/target/nacos-server-$version/nacos/bin

运行:
startup.cmd -m standalone 单机运行

3,子模块配置

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.56.1:8848
  application:
    name: product

4,启动类添加注解
@EnableDiscoveryClient

5,nacos 查看

127.0.0.1:8848
默认账号密码: nacos nacos
posted @ 2023-03-04 10:31  李很好  阅读(43)  评论(0)    收藏  举报