文章 《Spring Cloud 使用 Nacos 作配置中心》 描述了如何在 Spring Cloud 使用 Nacos 作配置中心的使用方法,本文在此基础上,使用 Nacos 作为 Spring Cloud 的注册中心。
安装 Nacos
为简单起见,这里使用单机版本的 Nacos Server 作为注册中心,安装过程可以参考 《Spring Cloud 使用 Nacos 作配置中心》。
服务提供者
服务提供者在文章 《Spring Cloud 使用 Nacos 作配置中心》 源代码 springcloudstudy 基础上进行开发。其中,springcloudstudy 作为父项目,服务提供者 nacosprovider 作为子项目。
添加 nacosprovider 的依赖:
<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>
其中,依赖 spring-cloud-starter-alibaba-nacos-discovery 用于连接 Nacos Server 注册中心。
bootstrap.yml 配置 Nacos Server 地址,以及服务名称:
server:
port: 8060

最低0.47元/天 解锁文章
5万+

被折叠的 条评论
为什么被折叠?



