Spring Boot 2.x 基础案例:整合Dubbo 2.7.3+Nacos1.1.3(最新版)

本文的思维导图

1、概述

本文将介绍如何基于Spring Boot 2.x的版本,通过Nacos作为配置与注册中心,实现Dubbo服务的注册与消费。

整合组件的版本说明:

Spring Boot 2.1.9

Dubbo 2.7.3

Nacos 1.1.3

本文的亮点:

1.采用yml方式进行dubbo的配置。

2.相关组件采用较新版本进行整合

3.相关源代码放置于Github上,可随时查看。

源代码放置Github: https://github.com/raysonfang/spring-boot-demo-all

之前公司在使用Dubbo 2.6.1的时候,采用Zookeeper作为注册中心。当时,也只是仅仅拿来作为注册中心使用,一没有专门的管理后台进行可视化管理操作,二是功能单一,仅作为注册中心使用。

经过一段时间的学习和了解以后,发现采用阿里开源的Nacos作为注册中心与外部配置中心。它比Zookeeper更适合做服务的注册与配置,毕竟是大厂开源,经过大量实践。

如果不清楚Nacos是什么,或具有什么主要功能以及架构设计思想。自行花点时间查一下资料。

Nacos:

注:此次主要实践Nacos作为注册中心,后面会单独整合Nacos作为配置中心的实践分享。

2、基础框架搭建

使用idea+maven多模块进行项目搭建

spring-boot-dubbo-nacos-demo:父工程

Spring Boot 2.x 基础案例:整合Dubbo 2.7.3+Nacos1.1.3(最新版)

shop-service-provider: dubbo服务提供者

Spring Boot 2.x 基础案例:整合Dubbo 2.7.3+Nacos1.1.3(最新版)

shop-service-consumer: dubbo服务消费者,是一个web工程

Spring Boot 2.x 基础案例:整合Dubbo 2.7.3+Nacos1.1.3(最新版)

3、pom.xml说明

spring-boot-dubbo-nacos-demo:父工程的pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.raysonblog</groupId> <artifactId>misco-dubbo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>misco-dubbo</name> <packaging>pom</packaging> <description>Demo project for Spring Boot Dubbo Nacos</description> <modules> <module>shop-service-provider</module> <module>shop-service-consumer</module> </modules> <properties> <java.version>1.8</java.version> <spring-boot.version>2.1.9.RELEASE</spring-boot.version> <dubbo.version>2.7.3</dubbo.version> </properties> <dependencyManagement> <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Apache Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Dubbo Spring Boot Starter --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> <repositories> <repository> <id>apache.snapshots.https</id> <name>Apache Development Snapshot Repository</name> <url>https://repository.apache.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjwzs.html