1、引入依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
2、配置文件配置
spring:
cloud:
nacos:
discovery:
server-addr: 120.77.181.202:8848 #nacos地址
application:
name: coupon # 注册的服务名 必须加,否则不能注册
3、启动类加@EnableDiscoveryClient 开启服务的注册与发现
@SpringBootApplication
@EnableDiscoveryClient
public class CouponApplication {
public static void main(String[] args) {
SpringApplication.run(CouponApplication.class, args);
}
}