1.引入依赖:
- 在父工程中添加spring-cloud-alibaba的管理依赖
-
<!-- Nacos的管理依赖--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
注意:spring-cloud-alibaba的版本号需要和springBoot的版本号适配一致
-
具体请看官网版本说明https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
在子模块引入依赖nacos客户端
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
2.yml文件配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/cloud_user?useSSL=false
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
application:
name: userserver
cloud:
nacos:
discovery:
server-addr: localhost:8848
配置好之后启动项目,完成nacos的服务注册
1.本地启动nacos
浏览器输入ip:端口/nacos/index.html