一.父模块创建
1.创建一个spring boot项目 名称为demo
2.在上面创建好的工程名demo上,点击右键,选择New–>Module,进入New Module页面 name为dubbo-server
3,再创建另一个Module,name为dubbo-client
4.删除无用的文件及文件夹,包括三个模块的mvnw、mvnw.cmd文件及.mvn文件夹,src目录,父模块只做依赖管理
5.配置父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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sun</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <!--<packaging>jar</packaging>--> <packaging>pom</packaging> <!--父模块打包类型必须为pom--> <modules> <module>dubbo-server</module> <module>dubbo-client</module> </modules> <name>demo</name> <description>Practice the learned code</description> <!-- parent指明继承关系,给出被继承的父项目的具体信息--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- 在properties中统一控制依赖包的版本,更清晰--> <dubbo.version>2.5.3</dubbo.version> <zkclient.version>0.10</zkclient.version> </properties> <dependencyManagement> <!--dependencyManagement用于管理依赖版本号--> <dependencies> <!-- 删除spring-boot-starter和spring-boot-starter-test, 因为parent中继承的祖先中已经有了,并且一般dependencyManagement管理的依赖都要写版本号 --> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter</artifactId>--> <!--</dependency>--> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-test</artifactId>--> <!--<scope>test</scope>--> <!--</dependency>--> <!--新增后续dubbo项目中所需依赖,dubbo、zk--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <!--<version>2.5.3</version>--> <!--使用properties中配置的版本号--> <version>${dubbo.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <!--<version>0.10</version>--> <!--使用properties中配置的版本号--> <version>${zkclient.version}</version> </dependency> </dependencies> </dependencyManagement> <!--该插件作用是打一个可运行的包,必须要写在需要打包的项目里。这里的父模块不需要打包运行,所以删掉该插件。--> <!--<build>--> <!--<plugins>--> <!--<plugin>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-maven-plugin</artifactId>--> <!--</plugin>--> <!--</plugins>--> <!--</build>--> </project>
6.dubbo-server\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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sun</groupId> <artifactId>dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>dubbo-server</name> <description>Demo project for Spring Boot</description> <!-- 子模块的parent要使用顶层的父模块--> <parent> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-parent</artifactId>--> <!--<version>1.5.8.RELEASE</version>--> <!--<relativePath/>--> <groupId>com.sun</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <!-- properties可删掉,会继承父模块的--> <!--<properties>--> <!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>--> <!--<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>--> <!--<java.version>1.8</java.version>--> <!--</properties>--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--新增后续dubbo项目中所需依赖,dubbo、zk。 父模块pom中使用dependencyManagement来管理依赖版本号,子模块pom中不需要再写版本号,exclusion也不需要--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <!--<version>2.5.3</version>--> <!--<exclusions>--> <!--<exclusion>--> <!--<groupId>org.springframework</groupId>--> <!--<artifactId>spring</artifactId>--> <!--</exclusion>--> <!--</exclusions>--> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <!--<version>0.10</version>--> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
7.dubbo-client/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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sun</groupId> <artifactId>dubbo-client</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>dubbo-client</name> <description>Demo project for Spring Boot</description> <!-- 子模块的parent要使用顶层的父模块--> <parent> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-parent</artifactId>--> <!--<version>1.5.8.RELEASE</version>--> <!--<relativePath/>--> <groupId>com.sun</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <!-- properties可删掉,会继承父模块的--> <!--<properties>--> <!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>--> <!--<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>--> <!--<java.version>1.8</java.version>--> <!--</properties>--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 该模块需要启动web服务,需要该依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--新增后续dubbo项目中所需依赖,dubbo、zk 父模块pom中使用dependencyManagement来管理依赖版本号,子模块pom中不需要再写版本号 父模块pom中里有exclusion,子模块pom中不要写exclusion--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <!--<version>2.5.3</version>--> <!--<exclusions>--> <!--<exclusion>--> <!--<groupId>org.springframework</groupId>--> <!--<artifactId>spring</artifactId>--> <!--</exclusion>--> <!--</exclusions>--> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <!--<version>0.10</version>--> </dependency> <!--client模块需要依赖server模块--> <dependency> <groupId>com.sun</groupId> <artifactId> dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
点击IDEA右侧的Maven Projects,在每个模块的Dependencies中即可查看每个dependency内部的依赖及版本号
原文地址:https://www.cnblogs.com/sunkang-work/p/12001374.html
时间: 2024-10-10 14:17:28