版本对应关系:
| Spring Cloud Alibaba Version | Spring Cloud Version | Spring Boot Version |
|---|---|---|
| 2021.1.1.0* | Spring Cloud 2021.1.1 | 2.6.3 |
| 2021.0.5.0* | Spring Cloud 2021.0.5 | 2.6.13 |
| 2021.0.4.0 | Spring Cloud 2021.0.4 | 2.6.11 |
| 2021.0.1.0 | Spring Cloud 2021.0.1 | 2.6.3 |
| 2021.1 | Spring Cloud 2020.0.1 | 2.4.2 |
| 2022.0.0.0* | Spring Cloud 2022.0.0 | 3.0.2 |
| 2022.0.0.0-RC2 | Spring Cloud 2022.0.0 | 3.0.2 |
| 2022.0.0.0-RC1 | Spring Cloud 2022.0.0 | 3.0.0 |
Nacos+Eureka双注册中心
1、 pom文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
2、配置yaml
eureka:
instance:
# 设置该服务注册中心的hostname
hostname: 127.0.0.1
client:
# 我们创建的是服务注册中心,而不是普通的应用,这个应用会向注册中心注册它自己
#,设置为false就是禁止自己向自己注册的这个种行为
register-with-eureka: false
# 不去检索其他的服务,因为注册中心本身的职责就是维护服务实例
fetch-registry: false
# 制定服务注册中心的位置
service-url.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848
username: nacos
passwrod: nacos
discovery:
namespace: dev # 命名空间。这里使用 dev 开发环境
metadata:
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
3、启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient // 开启 Spring Cloud 注册发现客户端
public class Application {
public static void main(String[] args) {
// 启动 Spring Boot 应用
SpringApplication.run(Application.class, args);
System.out.println("---------启动成功!------");
}
}
启动报错,只能有一个注册实例
修改配置
spring:
application:
name: doubleRegister
autoconfigure:
exclude: org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration,org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration
Nacos+Eureka注册注册成功
检查nacos
检查eureka
本文由博客一文多发平台 OpenWrite 发布!