《Apache Dubbo微服务开发从入门到精通》——快速开始,一个 Dubbo Spring Boot 示例——二、 深入示例源码(3) https://developer.aliyun.com/article/1225214
3) 添加Maven依赖
在初始化完项目以后,我们需要先添加Dubbo相关的maven依赖。
对于多模块项目,首先需要在父项目的pom.xml里面配置依赖信息。
编辑./pom.xml这个文件,添加下列配置。
<properties> <dubbo.version>3.2.0-beta.4</dubbo.version> <spring-boot.version>2.7.8</spring-boot.version> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </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> <!-- Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId> <version>${dubbo.version}</version> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> </plugin> </plugins> </pluginManagement> </build>
然后在dubbo-spring-boot-consumer和dubbo-spring-boot-provider两个模块pom.xml中进行具体依赖的配置。
编辑./dubbo-spring-boot-consumer/pom.xml和./dubbo-spring-boot-provider/pom.xml这两文件,都添加下列配置。
<dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-samples-spring-boot-interface</artifactId> <version>${project.parent.version}</version> </dependency> <!-- dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId> <type>pom</type> <exclusions> <exclusion> <artifactId>slf4j-reload4j</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <!-- spring boot starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> </dependencies>
在这份配置中,定义了dubbo和zookeeper(以及对应的连接器curator)的依赖。
添加了上述的配置以后,可以通过IDEA的Maven-Reload All Maven Projects刷新依赖。
《Apache Dubbo微服务开发从入门到精通》——快速开始,一个 Dubbo Spring Boot 示例——二、 深入示例源码(5) https://developer.aliyun.com/article/1225211