【Spring Cloud Alibaba】1.新版SpringCloudAlibaba整合Dubbo,配置多注册中心——Nacos+Zookeeper
1.背景介绍
新系统微服务体系使用 SpringCloudAibaba,版本为目前最新的2021.1;由于公司旧项目使用的技术栈为基于Dubbo+Zookeeper,新项目使用Nacos,且Dubbo支持同时注册多个注册中心,故而采用双注册的技术选型。
网上查询相关资料比较少,SpringCloudAibaba会出现各种依赖导致的问题,使用经反复测试及冲突解决、目前采用版本如下面模块所示,在这基础上进行调整可支持多个版本的Spring Cloud。
2.父模块pom.xml
1.8
1.8
8
8
2.5.5
2020.0.4
3.0.4
2021.1
3.1.4
2.6.6
2.6.7
1.1.3
3.4.13
4.1.68.Final
4.0.1
2.8.0
0.10
org.springframework.boot
spring-boot-dependencies
${spring.boot.version}
pom
import
org.springframework.cloud
spring-cloud-dependencies
${spring.cloud.version}
pom
import
com.alibaba.cloud
spring-cloud-alibaba-dependencies
${alibaba.cloud.version}
pom
import
org.springframework.cloud
spring-cloud-stream-dependencies
${stream.cloud.version}
pom
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-config
${alibaba.cloud.version}
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
${alibaba.cloud.version}
org.springframework.cloud
spring-cloud-starter-bootstrap
${spring.cloud.bootstrap.version}
com.alibaba
dubbo
${dubbo.version}
org.jboss.netty
netty
spring-context
org.springframework
com.alibaba
dubbo-registry-nacos
${dubbo.registry.nacos.version}
com.alibaba.nacos
nacos-client
${nacos.client.version}
io.netty
netty-all
${netty.all.version}
org.apache.curator
curator-framework
${curator.framework.version}
org.apache.curator
curator-recipes
${curator.recipes.version}
org.apache.zookeeper
zookeeper
${zookeeper.version}
pom
org.slf4j
slf4j-log4j12
com.101tec
zkclient
${zkclient.version}
3.子模块pom.xml(Dubbo)
org.springframework.cloud
spring-cloud-starter-bootstrap
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
com.alibaba
dubbo
org.jboss.netty
netty
spring-context
org.springframework
com.alibaba
dubbo-registry-nacos
com.alibaba.nacos
nacos-client
io.netty
netty-all
org.apache.curator
curator-framework
org.apache.curator
curator-recipes
com.101tec
zkclient
4.主要配置文件
########## nacos注册 ###########
#向Nacos注册中心注册
spring.cloud.nacos.discovery.register-enabled = true
#Nacos注册地址
spring.cloud.nacos.discovery.server-addr = 127.0.0.1:8848,127.0.0.2:8848
########## Dubbo ###########
#对应常见的传输协议:Dubbo、RMI、Hessain、WebService、Http
dubbo.protocol.name = dubbo
#设置端口为 -1 表示 dubbo 自动扫描并使用可用端口(从20880开始递增),避免了端口冲突的问题
dubbo.protocol.port = -1
#注册地址
dubbo.registry.address = nacos://127.0.0.1:8848;nacos://127.0.0.2|zookeeper://127.0.0.1:2181?backup=127.0.0.2:2182,127.0.0.3:2183
#dubbo提供者名称
dubbo.application.name = dubbo-demo
5.启动类
package cn.com;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author jiangyf
* @description: 网关服务启动类
* @date 2021/11/30
*/
@EnableDubbo(scanBasePackages = "cn.com.bluemoon.aad")
@SpringBootApplication
public class DubboDemoApplication {
public static void main(String[] args) {
SpringApplication.run(DubboDemoApplication.class, args);
}
}
ps:看到这里,如果能解决你的问题,麻烦点个关注支持一下,谢谢~