springcloud alibaba nacos discovery

1.下载安装nacos

springalibaba官方文档看github wiki. 为了打开方便就直接把地址粘贴过来:https://github.com/alibaba/spring-cloud-alibaba/wiki/Nacos-discovery

将nacos下载并解压

 

 打开bin目录startup.cmd启动nacos

打开: http://localhost:8848/nacos    用户名/密码:nacos/nacos

 

 安装并启动成功

 

2.代码

 官方文档写的很细,大概罗列一下:

消费端和生产者都加以下pom和yml:

    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>
server:
  port: 具体端口
spring:
  application:
    name: nacos-provider-payment
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

management:
  endpoints:
    web:
      exposure:
        include: "*"

 

 

 

 

服务调用就用RestTemplate, ribbon(nacos discovery的jar里已经整合了ribbon)

代码:https://github.com/lulu4pix/springcloud/commit/c683aea0deb7a62fe4977e458a060022ecae6fd7

 

3.测试

 

 

 

 

 

posted @ 2021-05-29 18:30  圣金巫灵  阅读(699)  评论(0编辑  收藏  举报