使用Nacos注册中心
Nacos可以替代Eureka作为注册中心,不过Nacos是一个独立的组件,首先需要将Nacos下载启动起来(默认是8848端口),然后在进行服务注册
依赖
1 2 3 4 5
| <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>
|
配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| spring: application: name: springcloudalibaba-provider-nacos cloud: nacos: discovery: server-addr: localhost:8848
management: endpoints: web: exposure: include: '*'
|
启动类
1 2 3 4 5 6 7 8 9
| @SpringBootApplication @EnableDiscoveryClient public class ProviderNacosApp {
public static void main(String[] args) { SpringApplication.run(ProviderNacosApp.class,args); }
}
|