文章导读:
1、介绍文章内容的版本依赖
2、创建Springboot基础工程
3、修改基础工程的配置文件
4、增加dubbo 3的依赖包管理
5、建立子工程演示
6、修改父工程和子工程的POM配置文件
7、添加日志文件和默认端口号
1、相关依赖版本
依赖 | 版本 |
---|---|
Springboot | 2.5.x |
dubbo | 3.X |
2、创建Springboot基础工程
由于我们采用的是bom的形式,父工程暂时不需要引入任何依赖
备课和讲课的电脑可能不一样,所以讲课的时候可能物理位置不是这个,哈哈!~
3、修改配置文件
原始配置文件如下:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jiangzh.course</groupId>
<artifactId>dubbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbo_3_study</name>
<description>dubbo_3学习</description>
<properties>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
修改以后的配置文件:【修改的内容都使用注释进行了概括,直接寻找有注释的位置即可】
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jiangzh.course</groupId>
<!-- 修改个逼格更高的artifactId -->
<artifactId>dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 增加packaging类型 -->
<packaging>pom</packaging>
<name>dubbo_3_study</name>
<description>dubbo_3学习</description>
<properties>
<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>
</dependencies>
-->
<!-- 父工程做依赖包的管理 -->
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<!-- 移除springboot的打包管理,后续在子工程中进行单独处理 -->
<!--
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
-->
</project>
4、增加dubbo 3的依赖包管理
1、在pom.xml 中的properties中增加dubbo的版本号配置
<properties>
<java.version>1.8</java.version>
<!-- 增加dubbo版本号控制 -->
<dubbo.version>3.0.0.preview</dubbo.version>
</properties>
2、在pom.xml中,增加dependencyManagement相关的依赖管理
<!-- 父工程做依赖包的管理 -->
<dependencyManagement>
<dependencies>
<!-- 增加dubbo依赖包管理 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.65.Final</version>
</dependency>
</dependencies>
</dependencyManagement>
5、建立子工程示例
重复建立父工程时的步骤
6、修改父工程和子工程的POM配置文件
6.1 修改子工程的POM配置文件
配置文件位置:
修改之前:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jiangzh.course</groupId>
<artifactId>dubbo-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbo-demo</name>
<description>演示子工程创建</description>
<properties>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
修改之后:【修改的内容都使用注释进行了概括,直接寻找有注释的位置即可】
<?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>
<parent>
<!-- 将Springboot的父工程依赖修改为自己的父工程, 这样可以继承父工程中的Springboot依赖 -->
<groupId>com.jiangzh.course</groupId>
<artifactId>dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.jiangzh.course</groupId>
<artifactId>dubbo-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbo-demo</name>
<description>演示子工程创建</description>
<properties>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
6.2 修改父工程的POM配置文件
7、添加日志文件和默认端口号
server:
port: 8080
logging:
config: classpath:logback.xml
7.1 增加日志配置
配置文件内容:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%highlight(%-5level) (%file:%line\)- %m%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>