导读:本篇做为SpringCloud Alibaba微服务实战系列的第四篇,咱们对以前的微服务框架进行优化,经过Maven bom机制管理全部组件的版本。html
BOM(Bill of Materials)是由Maven提供的功能,它经过定义一整套相互兼容的jar包版本集合,使用时只须要依赖该BOM文件,便可放心的使用须要的依赖jar包,且无需再指定版本号。BOM的维护方负责版本升级,并保证BOM中定义的jar包版本之间的兼容性。java
使用BOM除了能够方便使用者在声明依赖的客户端时不须要指定版本号外,最主要的缘由是能够解决依赖冲突,防止你项目中出现 NoSuchMethodError
, ClassNotFoundException
等不可控的异常。mysql
在SpringCloud项目体系中咱们约定跟SpringCloud版本相关的用主pom文件进行版本控制,对于第三方组件或者公共模块的版本使用自定义的bom进行控制,接下来咱们一步步对原有框架进行改造。sql
<?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.jianzh5.cloud</groupId>
<artifactId>cloud-bom</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<properties>
<mybatis-plus.version>3.1.1</mybatis-plus.version>
<mysql.version>5.1.47</mysql.version>
<cloud-alibaba.version>1.0.0</cloud-alibaba.version>
</properties>
<!--管理全部第三方jar包版本,SpringCloud Alibaba 版本由主Pom控制-->
<dependencyManagement>
<dependencies>
<!--cloud-common 版本-->
<dependency>
<groupId>com.jianzh5.cloud</groupId>
<artifactId>cloud-common</artifactId>
<version>${cloud-alibaba.version}</version>
</dependency>
<dependency>
<groupId>com.jianzh5.cloud</groupId>
<artifactId>account-feign</artifactId>
<version>${cloud-alibaba.version}</version>
</dependency>
<dependency>
<groupId>com.jianzh5.cloud</groupId>
<artifactId>product-feign</artifactId>
<version>${cloud-alibaba.version}</version>
</dependency>
<!--database-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</repository>
</repositories>
</project>复制代码
注意,这个模块不要再定义
The build could not read 1 project -> [Help 1]
The project com.jianzh5.cloud:cloud-aliaba:1.0.0 (D:\project_jianzh5\cloud-aliaba\pom.xml) has 1 error
The dependencies of type=pom and with scope=import form a cycle: com.jianzh5.cloud:cloud-bom:1.0.0 -> com.jianzh5.cloud:cloud-bom:1.0.0 @ com.jianzh5.cloud:cloud-bom:1.0.0
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:复制代码
<!--统一版本-->
<dependency>
<groupId>com.jianzh5.cloud</groupId>
<artifactId>cloud-bom</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>复制代码
此段内容须要放在dependencyManagement中第一个位置微信
定义,如: <dependency>
<groupId>com.jianzh5.cloud</groupId>
<artifactId>cloud-common</artifactId>
</dependency>复制代码
至此咱们已经完成了项目的统一版本管理,那么本期的“SpringCloud Alibaba微服务实战四 - 版本管理”篇也就该结束啦,我们下期有缘再见!mybatis
系列文章框架
欢迎扫码关注微信公众号或 我的博客maven