nacos 服务注册与发现(注册中心)
作者:互联网
1,首先,修改 pom.xml 文件,引入 Nacos Discovery Starter。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<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>
2,在应用的 /src/main/resources/application.properties 配置文件中配置 Nacos Server 地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
或application.yml中配置
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: mall-coupon
3,启动类开启 @EnableDiscoveryClient 注解
@SpringBootApplication
@EnableDiscoveryClient
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
nacos 中心即可看到如下已注册服务
标签:服务,spring,nacos,alibaba,application,注册,cloud,discovery 来源: https://blog.csdn.net/weixin_44371237/article/details/121921940