将nacos作为注册中心使用
使用的步骤
-
导入nacos依赖
这么导
<dependencies>
<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.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- 去官方github仓库下载
nacos-server
,然后bin>start up启动
下载链接:https://github.com/alibaba/nacos/releases
-
给你想注册的服务加上名字,然后修改他们的application.yml,主启动类加上注释
application: name: coupon
主启动类
package com.eng.gulishopping;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableDiscoveryClient
@SpringBootApplication
public class EngCouponApplication {
public static void main(String[] args) {
SpringApplication.run(EngCouponApplication.class, args);
}
}