人生就象弈棋, 一步失误, 全盘皆输,这是令人悲哀之事;而且人生还不如弈棋,不可能再来一局,也不能悔棋。—— 弗洛伊德

下载

image-20210303220929574

找到zip下载解压即可

进入bin目录

1
2
# 单机启动
startup.cmd -m standalone

image-20210303221053991

然后我们可以引入javaSDK

使用mavenGAV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<dependencies>
<!-- alibaba cloud -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

然后是bootstrap.yml

1
2
3
4
5
6
7
spring:
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
application:
name: ruben-provider

启动项目可以看到日志输出

image-20210303222515963

然后访问nacos控制台

image-20210303222855121

输入默认用户名nacos密码nacos

也能看到我们的nacos单机节点正常运行

image-20210303223003484

在主启动类中配置@EnableDiscoveryClient

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.ruben;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@EnableDiscoveryClient
@SpringBootApplication
@MapperScan({"com.ruben.dao.xml"})
public class SimpleSpringbootApplication {

public static void main(String[] args) {
SpringApplication.run(SimpleSpringbootApplication.class, args);
}

}

启动后可以看到服务已经注册成功

image-20210304212612855